Adding XMPMeta with PDFBox - pdfbox

I try to implement XMP using PDFBOX Library.
I try to output the following XML data:
<rdf:Description xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/" xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#" xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#" rdf:about="">
<pdfaExtension:schemas>
<rdf:Bag>
<rdf:li rdf:parseType="Resource">
<pdfaSchema:schema>Factur-X PDFA Extension Schema</pdfaSchema:schema>
<pdfaSchema:namespaceURI>urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#</pdfaSchema:namespaceURI>
<pdfaSchema:prefix>fx</pdfaSchema:prefix>
<pdfaSchema:property>
<rdf:Seq>
<rdf:li rdf:parseType="Resource">
<pdfaProperty:name>DocumentFileName</pdfaProperty:name>
<pdfaProperty:valueType>Text</pdfaProperty:valueType>
<pdfaProperty:category>external</pdfaProperty:category>
<pdfaProperty:description>name of the embedded XML invoice file</pdfaProperty:description>
</rdf:li>
...
<rdf:li rdf:parseType="Resource">
<pdfaProperty:name>ConformanceLevel</pdfaProperty:name>
<pdfaProperty:valueType>Text</pdfaProperty:valueType>
<pdfaProperty:category>external</pdfaProperty:category>
<pdfaProperty:description>The conformance level of the embedded Factur-X data</pdfaProperty:description>
</rdf:li>
</rdf:Seq>
</pdfaSchema:property>
</rdf:li>
</rdf:Bag>
</pdfaExtension:schemas>
</rdf:Description>
For this I used a XMPSchema object to build it :
XMPSchema pdfaExtension = xmp.createAndAddXMPBasicSchema();
pdfaExtension.setNamespace("http://www.aiim.org/pdfa/ns/extension/");
pdfaExtension.setPrefix("pdfaExtension");
pdfaExtension.addBagValueAsSimple("schemas", "schemas");
This allow me to generate the following:
<pdfaExtension:schemas>
<rdf:Bag>
<rdf:li>schemas</rdf:li>
</rdf:Bag>
</pdfaExtension:schemas>
My issue is to create "nodes" under the rdf:li tag.
I tried using the following methods :
pdfaExtension.addBagValueAsSimple("schemas", "schemas");
pdfaExtension.addQualifiedBagValue("BagContainer", "Value3");
pdfaExtension.addUnqualifiedSequenceValue("SeqContainer", "Value1");
pdfaExtension.addProperty(xmp.getTypeMapping()
.createText(null, "test", "simpleProperty", "Hello"));
Unfortunatelly, I do not retrieve the correct output.

Related

Problems with SPARQL Tutorial - A First SPARQL Query

I'm a starter to the sparql, following the sparql tutorial from https://jena.apache.org/tutorials/sparql_query1.html
I used the sparql query function like this:
caihanzhi#ererererermaodeMacBook-Air bin % sparql --data=/Users/caihanzhi/Desktop/vc-db-1.rdf --query=/Users/caihanzhi/Desktop/q1.rq
and the vc-db-1.rdf is
<rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:vCard='http://www.w3.org/2001/vcard-rdf/3.0#'
>
<rdf:Description rdf:about="http://somewhere/JohnSmith">
<vCard:FN>John Smith</vCard:FN>
<vCard:N rdf:parseType="Resource">
<vCard:Family>Smith</vCard:Family>
<vCard:Given>John</vCard:Given>
</vCard:N>
</rdf:Description>
<rdf:Description rdf:about="http://somewhere/RebeccaSmith">
<vCard:FN>Becky Smith</vCard:FN>
<vCard:N rdf:parseType="Resource">
<vCard:Family>Smith</vCard:Family>
<vCard:Given>Rebecca</vCard:Given>
</vCard:N>
</rdf:Description>
<rdf:Description rdf:about="http://somewhere/SarahJones">
<vCard:FN>Sarah Jones</vCard:FN>
<vCard:N rdf:parseType="Resource">
<vCard:Family>Jones</vCard:Family>
<vCard:Given>Sarah</vCard:Given>
</vCard:N>
</rdf:Description>
<rdf:Description rdf:about="http://somewhere/MattJones">
<vCard:FN>Matt Jones</vCard:FN>
<vCard:N
vCard:Family="Jones"
vCard:Given="Matthew"/>
</rdf:Description>
</rdf:RDF>
And the q1.rq is
SELECT ?x
WHERE { ?x <http://www.w3.org/2001/vcard-rdf/3.0#FN> "John Smith" }
But it failed to query. Bash told me that:
Encountered " "{" "{ "" at line 1, column 1.
Was expecting one of:
"\ufeff" ...
"base" ...
"prefix" ...
"select" ...
"describe" ...
"construct" ...
"ask" ...
if anyone knows how to solve it please do not hesitate to provide help!

How to list all elements of the selected enumerations with the use of SPARQL?

The following is a subquestion to my previous question: available here.
How to modify the following SPARQL query:
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?dt ?element ?elementType {
?dt a rdfs:Datatype ;
owl:oneOf/rdf:rest*/rdf:first ?element .
bind(datatype(?element) as ?elementType)
}
in order to to get a result of only A and C? I would like to obtain { "a1" "a2" "c1" "c2" }. The above query returns all enumeration values from the ontology, I mean: { "a1" "a2" "b1" "b2" "c1" "c2" }
We are given the ontology (A and B are equivalent but presented in different style syntax):
Variant A) in the functional style syntax:
Prefix(ont:=<http://www/ont.owl#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Ontology(<http://www/ont.owl>
DatatypeDefinition( ont:A DataOneOf( "a1" "a2" ) )
DatatypeDefinition( ont:B DataOneOf( "b1" "b2" ) )
DatatypeDefinition( ont:C DataOneOf( "c1" "c2" ) )
)
Variant B) in the RDF/XML style syntax:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY ont "http://www/ont.owl#" >
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY xml "http://www.w3.org/XML/1998/namespace" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<rdf:RDF xmlns="http://www/ont.owl#"
xml:base="http://www/ont.owl"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:ont="http://www/ont.owl#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace">
<owl:Ontology rdf:about="http://www/ont.owl"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Datatypes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www/ont.owl#A -->
<rdfs:Datatype rdf:about="&ont;A">
<owl:equivalentClass>
<rdfs:Datatype>
<owl:oneOf>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>a1</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>a2</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</owl:oneOf>
</rdfs:Datatype>
</owl:equivalentClass>
</rdfs:Datatype>
<!-- http://www/ont.owl#B -->
<rdfs:Datatype rdf:about="&ont;B">
<owl:equivalentClass>
<rdfs:Datatype>
<owl:oneOf>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>b1</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>b2</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</owl:oneOf>
</rdfs:Datatype>
</owl:equivalentClass>
</rdfs:Datatype>
<!-- http://www/ont.owl#C -->
<rdfs:Datatype rdf:about="&ont;C">
<owl:equivalentClass>
<rdfs:Datatype>
<owl:oneOf>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>c1</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>c2</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</owl:oneOf>
</rdfs:Datatype>
</owl:equivalentClass>
</rdfs:Datatype>
</rdf:RDF>
<!-- Generated by the OWL API (version 3.4.2) http://owlapi.sourceforge.net -->
As I said in the comments on the previous answer:
#Annabelle I was basing the retrieval methods on the ontology that I provided. There are certainly other ways to select the data types if they're identified by IRIs. In your case, it looks like it would be values ?dt {:A :B } if you only want ?dt to be A or B.
and
In this case, note that the axiom is encoded by saying that :A is owl:equivalentClass to the datatype class expression. That's the extra link you need between the class IRI and the expression.
That gives us:
select ?dt ?element ?elementType {
values ?dt { ont:A ont:B }
?dt owl:equivalentClass/a rdfs:Datatype ;
owl:oneOf/rdf:rest*/rdf:first ?element .
bind(datatype(?element) as ?elementType)
}
This really isn't much different from the previous answer. You just need to add on the specific values that you're looking for, and then add the equivalentClass link.

How To Parse XDocument (Ebay) Items (List) Using Visual Basic?

<code>
For Each oXElement In oXDocument.Descendants("searchResult")
sTitle = oXElement.Element("title").Value
Next
</code>
I have also tried:
<code>
For Each oXElement In oXDocument.Elements(searchResults)
sTitle = oXElement.Element("title").Value
Next
</code>
I am having trouble getting a hold of nodes as well as understanding the way you communicate with XDocument nodes.
My Ultimate goal is to create an Ebay Object Model From all Ebay Element's Attributes. For that I need to refer to XML tag somehow - and this is where I would appreciate your advice or sample example that could let me proceed with parsing out this XML response.
Thank you all much for any help.
PS: I have searched for a similar questions and found a few of the same kind but still could not get my parsing to work.
<findItemsByProductResponse xmlns="http://www.ebay.com/marketplace/search/v1/services">
<ack>Success</ack>
<version>1.12.0</version>
<timestamp>2013-06-02T22:42:04.500Z</timestamp>
<searchResult count="5">
<item>
<itemId>370821427802</itemId>
<title>
Modern Database Management 11E by Hoffer, Ramesh, Topi 11th (Int'l Edition)
</title>
<globalId>EBAY-US</globalId>
<primaryCategory>
<categoryId>2228</categoryId>
<categoryName>Textbooks, Education</categoryName>
</primaryCategory>
<galleryURL>
http://thumbs3.ebaystatic.com/m/meSAqCRbXecSjZjO1833dWQ/140.jpg
</galleryURL>
<viewItemURL>
http://www.ebay.com/itm/Modern-Database-Management-11E-Hoffer-Ramesh-Topi-11th-Intl-Edition-/370821427802?pt=US_Texbook_Education
</viewItemURL>
<productId type="ReferenceID">143649496</productId>
<paymentMethod>PayPal</paymentMethod>
<autoPay>true</autoPay>
<location>Malaysia</location>
<country>MY</country>
<shippingInfo>
<shippingServiceCost currencyId="USD">0.0</shippingServiceCost>
<shippingType>Free</shippingType>
<shipToLocations>Worldwide</shipToLocations>
<expeditedShipping>true</expeditedShipping>
<oneDayShippingAvailable>false</oneDayShippingAvailable>
<handlingTime>1</handlingTime>
</shippingInfo>
<sellingStatus>
<currentPrice currencyId="USD">54.07</currentPrice>
<convertedCurrentPrice currencyId="USD">54.07</convertedCurrentPrice>
<sellingState>Active</sellingState>
<timeLeft>P20DT10H47M20S</timeLeft>
</sellingStatus>
<listingInfo>
<bestOfferEnabled>false</bestOfferEnabled>
<buyItNowAvailable>false</buyItNowAvailable>
<startTime>2013-05-24T09:25:25.000Z</startTime>
<endTime>2013-06-23T09:29:24.000Z</endTime>
<listingType>StoreInventory</listingType>
<gift>false</gift>
</listingInfo>
<returnsAccepted>true</returnsAccepted>
<condition>
<conditionId>1000</conditionId>
<conditionDisplayName>Brand New</conditionDisplayName>
</condition>
<isMultiVariationListing>false</isMultiVariationListing>
<topRatedListing>true</topRatedListing>
</item>
<item>...</item>
<item>...</item>
<item>...</item>
<item>...</item>
</searchResult>
<paginationOutput>
<pageNumber>1</pageNumber>
<entriesPerPage>5</entriesPerPage>
<totalPages>3</totalPages>
<totalEntries>14</totalEntries>
</paginationOutput>
<itemSearchURL>
http://www.ebay.com/ctg/143649496?LH_BIN=1&_ddo=1&_incaucbin=0&_ipg=5&_pgn=1
</itemSearchURL>
</findItemsByProductResponse>
You have to use XNamespace instance when querying your XML:
Dim ns = XNamespace.Get("http://www.ebay.com/marketplace/search/v1/services")
And with that add it to every Descendants, Elements, Element, Attributes, Attributes, etc. calls you make:
For Each oXElement In oXDocument.Descendants(ns + "searchResult")
sTitle = oXElement.Element(ns + "title").Value
Next
For Each oXElement In oXDocument.Elements(ns + searchResults)
sTitle = oXElement.Element(ns + "title").Value
Next
Two things. First, you fell into the trap that catches 90% of the people with problems using LINQ to XML. You forgot the namespace. You can use the following which works in C# or VB:
Dim ns = XNamespace.Get("http://www.ebay.com/marketplace/search/v1/services")
VB Also lets you use a Imports for a namespace just as you import other .Net namespaces at the top of your file. The advantage of this option is that if you have a schema in your project, you get intellisense over the XML structure while building your query.
Imports <xmlns:eb="http://www.ebay.com/marketplace/search/v1/services">
The second issue you have is that the title element is not a direct child of searchResult, but is nested an additional level deeper. Here's a sample leveraging the imports for the namespace. I'm using the VB XML Literals for descendents (...) for contrast with anyone giving you a C# biased answer ;-)
Public Class XmlTest
Public Sub TestXml()
Dim data = <findItemsByProductResponse xmlns="http://www.ebay.com/marketplace/search/v1/services">
<ack>Success</ack>
<version>1.12.0</version>
<timestamp>2013-06-02T22:42:04.500Z</timestamp>
<searchResult count="5">
<item>
<itemId>370821427802</itemId>
<title>
Modern Database Management 11E by Hoffer, Ramesh, Topi 11th (Int'l Edition)
</title>
<globalId>EBAY-US</globalId>
<primaryCategory>
<categoryId>2228</categoryId>
<categoryName>Textbooks, Education</categoryName>
</primaryCategory>
<galleryURL>
http://thumbs3.ebaystatic.com/m/meSAqCRbXecSjZjO1833dWQ/140.jpg
</galleryURL>
<viewItemURL>
http://www.ebay.com/itm/Modern-Database-Management-11E-Hoffer-Ramesh-Topi-11th-Intl-Edition-/370821427802?pt=US_Texbook_Education
</viewItemURL>
<productId type="ReferenceID">143649496</productId>
<paymentMethod>PayPal</paymentMethod>
<autoPay>true</autoPay>
<location>Malaysia</location>
<country>MY</country>
<shippingInfo>
<shippingServiceCost currencyId="USD">0.0</shippingServiceCost>
<shippingType>Free</shippingType>
<shipToLocations>Worldwide</shipToLocations>
<expeditedShipping>true</expeditedShipping>
<oneDayShippingAvailable>false</oneDayShippingAvailable>
<handlingTime>1</handlingTime>
</shippingInfo>
<sellingStatus>
<currentPrice currencyId="USD">54.07</currentPrice>
<convertedCurrentPrice currencyId="USD">54.07</convertedCurrentPrice>
<sellingState>Active</sellingState>
<timeLeft>P20DT10H47M20S</timeLeft>
</sellingStatus>
<listingInfo>
<bestOfferEnabled>false</bestOfferEnabled>
<buyItNowAvailable>false</buyItNowAvailable>
<startTime>2013-05-24T09:25:25.000Z</startTime>
<endTime>2013-06-23T09:29:24.000Z</endTime>
<listingType>StoreInventory</listingType>
<gift>false</gift>
</listingInfo>
<returnsAccepted>true</returnsAccepted>
<condition>
<conditionId>1000</conditionId>
<conditionDisplayName>Brand New</conditionDisplayName>
</condition>
<isMultiVariationListing>false</isMultiVariationListing>
<topRatedListing>true</topRatedListing>
</item>
<item>...</item>
<item>...</item>
<item>...</item>
<item>...</item>
</searchResult>
<paginationOutput>
<pageNumber>1</pageNumber>
<entriesPerPage>5</entriesPerPage>
<totalPages>3</totalPages>
<totalEntries>14</totalEntries>
</paginationOutput>
</findItemsByProductResponse>
For Each el In data...<eb:searchResult>
Console.WriteLine(el...<eb:title>.Value)
Next
End Sub
End Class

Issues with Jena OWL reasoner

I am new to Jena but now encountered with some problems. I have a superclass Query Processing and its four subclasses:
Query Processing
— Query intent
— Query reformulation
— Query representation
— Query suggestion
When I use:
PREFIX Article: <http://www.semanticweb.org/aero/ontologies/computer-science#>
SELECT ?paper ?category
WHERE
{
?paper Article:inQueryIntent ?category .
}
Or with any the other 3 subclasses as the predicate like inQueryReformulation I can get the correct answer.
However when I used ?article Article:inQueryProcessing ?category which should return all the individuals related to the sub-classes QueryProcessing I got nothing. inQueryIntent (and the other 3) and inQueryProcessing are the object properties.
Here is my code:
Dataset dataset = TDBFactory.createDataset(directory);
Model model = dataset.getNamedModel(modelName);
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF, model);
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
InfModel infModel = ModelFactory.createInfModel(reasoner, ontModel);
Query query = QueryFactory.create(queryString);
QueryExecution queryExe = QueryExecutionFactory.create(query, infModel);
here is the ontology snippet :
object properties:
<!-- http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#inQueryIntent -->
<owl:ObjectProperty rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#inQueryIntent">
<rdf:type rdf:resource="&owl;FunctionalProperty"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Query_intent"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#article"/>
<rdfs:subPropertyOf rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#inInformationRetrievalQueryProcessing"/>
</owl:ObjectProperty>
class:
<owl:Class rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Query_intent">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Information_retrieval_query_processing"/>
</owl:Class>
individual:
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Classifying_Web_Queries_by_Topic_and_User_Intent">
<rdf:type rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#article"/>
<hasAuthor rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Bernard_J._Jansen"/>
<inQueryIntent rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Query_intent"/>
</owl:NamedIndividual>
I just build a domain ontology in ComputerScience, all the classes are concepts (like query processing is a superclass and query intent/reformulation/… are subclasses) in hierarchy and, all the papers and their corresponding authors are the individuals

in owl "Dl query" how to use advanced valu query in protege

I am developing an ontology and I have a problem with my Dl query
there is a class called "flower"
and this class has subclasses which are some flowers names
and also there is another class called "flowersColor"
and it has these values ("red","green" and "blue") as individuals-not subclass-
every flower has one color or more
I want to search for a flower that has red color and only red
my DL Query is :
"flower and hasColor value red"
this query will give me all flowers that has the color red even if it has other colors
however I want all flowers that has ONLY the color red
I want to write something like this
"flower and hasColor only value red" <- this is not correct grammatically
I main if the color has a combination of "red" and "green" then I don't want to see it in my result
I hope you can help me in my query
Thanks
Remember that OWL uses the open world assumption, so you are somewhat limited in what can be inferred via description logic.
So your "query", as Kaarel mentions, could be:
flower and (hasColor only {red})
Yet this is unprovable in the open world assumption. There could be statement, somewhere in the universe, which asserts:
<RedRose> :hasColor :StackOverflow .
Which, when combined with your assertions (which you're trying to query):
<RedRose> :hasColor :Red .
<RedRose> a :Flower .
Will cause the DL query to return no results. So due to the open world assumption, and the theoretical existence of wild, inaccurate, and irrelevant assertions (at least from your perspective), the DL query will fail, since it can only infer statements it can prove are true.
However, your example query can be used in an OWL restriction to determine if something is not something else. As an example, if you have a class (:OnlyRedFlower) which must only have the color red, but it has the color blue (you've asserted this additional color), then you can infer that this new flower is not in the set of :OnlyRedFlower.
Update: For those that are interested in trying this themselves, here's the ontology I created based on this question:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY owl2xml "http://www.w3.org/2006/12/owl2-xml#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY onto "http://www.elastra.com/onto/2009/5/30/onto.owl#" >
]>
<rdf:RDF xmlns="http://stackoverflow.com/users/64881/ontology_842588.rdf#"
xml:base="http://stackoverflow.com/users/64881/ontology_842588.rdf"
xmlns:owl2xml="http://www.w3.org/2006/12/owl2-xml#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:onto="http://www.elastra.com/onto/2009/5/30/onto.owl#">
<owl:Ontology rdf:about="">
<rdfs:comment xml:lang="en"
>Example for http://stackoverflow.com/questions/842588/in-owl-dl-query-how-to-use-advanced-valu-query-in-protege</rdfs:comment>
</owl:Ontology>
<owl:ObjectProperty rdf:about="&onto;hasColor"/>
<owl:Class rdf:about="&onto;Color"/>
<owl:Class rdf:about="&onto;ExampleFlower">
<rdfs:subClassOf rdf:resource="&onto;Flower"/>
</owl:Class>
<owl:Class rdf:about="&onto;Flower"/>
<owl:Class rdf:about="&onto;OnlyRedFlower">
<owl:equivalentClass>
<owl:Class>
<owl:intersectionOf rdf:parseType="Collection">
<rdf:Description rdf:about="&onto;Flower"/>
<owl:Restriction>
<owl:onProperty rdf:resource="&onto;hasColor"/>
<owl:allValuesFrom>
<owl:Class>
<owl:oneOf rdf:parseType="Collection">
<rdf:Description rdf:about="&onto;Red"/>
</owl:oneOf>
</owl:Class>
</owl:allValuesFrom>
</owl:Restriction>
</owl:intersectionOf>
</owl:Class>
</owl:equivalentClass>
<rdfs:subClassOf rdf:resource="&onto;Flower"/>
</owl:Class>
<owl:Class rdf:about="&onto;OtherFlower">
<rdfs:subClassOf rdf:resource="&onto;Flower"/>
</owl:Class>
<onto:Color rdf:about="&onto;Blue">
<rdf:type rdf:resource="&owl;Thing"/>
</onto:Color>
<onto:Flower rdf:about="&onto;BlueOrchid">
<rdf:type rdf:resource="&owl;Thing"/>
<onto:hasColor rdf:resource="&onto;Blue"/>
</onto:Flower>
<onto:Color rdf:about="&onto;Red">
<rdf:type rdf:resource="&owl;Thing"/>
</onto:Color>
<onto:Flower rdf:about="&onto;RedRose">
<rdf:type rdf:resource="&owl;Thing"/>
<onto:hasColor rdf:resource="&onto;Red"/>
</onto:Flower>
</rdf:RDF>
The query that you are after is:
flower and (hasColor only {red})
Note that the {.} constructor creates a class from an individual, or a list of individuals. So you can use it everywhere where a class is syntactically required, e.g.
(not {blue}) subClassOf
{red} and {green,blue} or (hasColor max 10 ({red} or {blue}))