OWLAPI : "ParserException" while converting String to Class Expression using ManchesterOWLSyntaxParser - java
I want to add new axiom into ontology, for that I created method which converts String [which is in Manchester OWL Syntax] into OWLClassExpression using ManchesterOWLSyntaxParser and later form new OWLAxiom and add to Ontology.
But I am getting following Exception (org.semanticweb.owlapi.manchestersyntax.renderer.ParserException) :-
Exception in thread "main" org.semanticweb.owlapi.manchestersyntax.renderer.ParserException: Encountered owl:real at line 1 column 12. Expected one of:
Datatype name
not
{
at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl$ExceptionBuilder.build(ManchesterOWLSyntaxParserImpl.java:2441)
at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseDataRangePrimary(ManchesterOWLSyntaxParserImpl.java:813)
at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseDataUnionOf(ManchesterOWLSyntaxParserImpl.java:756)
at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseDataIntersectionOf(ManchesterOWLSyntaxParserImpl.java:737)
at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseDataRange(ManchesterOWLSyntaxParserImpl.java:729)
at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseDataRestriction(ManchesterOWLSyntaxParserImpl.java:695)
at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseNonNaryClassExpression(ManchesterOWLSyntaxParserImpl.java:584)
at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseIntersection(ManchesterOWLSyntaxParserImpl.java:488)
at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseUnion(ManchesterOWLSyntaxParserImpl.java:511)
at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseClassExpression(ManchesterOWLSyntaxParserImpl.java:470)
at OWLAPI.convertStringToClassExpression(OWLAPI.java:29)
Following is my Ontology :-
<?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 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.semanticweb.org/empty#"
xml:base="http://www.semanticweb.org/empty"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://www.semanticweb.org/empty"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Data properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/empty#name -->
<owl:DatatypeProperty rdf:about="http://www.semanticweb.org/empty#name"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/empty#A -->
<owl:Class rdf:about="http://www.semanticweb.org/empty#A"/>
</rdf:RDF>
<!-- Generated by the OWL API (version 3.5.1) http://owlapi.sourceforge.net -->
My JAVA code is :-
// some code above to form OWLManager and Ontology
System.out.println(convertStringToClassExpression("name max 1 owl:real"));
private OWLClassExpression convertStringToClassExpression(String expression) {
ManchesterOWLSyntaxParser parser = OWLManager.createManchesterParser();
parser.setStringToParse(expression);
parser.setDefaultOntology(owlOntology); // my ontology
ShortFormEntityChecker checker = new ShortFormEntityChecker(getShortFormProvider());
parser.setOWLEntityChecker(checker);
return parser.parseClassExpression();
}
private BidirectionalShortFormProvider getShortFormProvider() {
Set<OWLOntology> ontologies = owlManager.getOntologies(); // my OWLOntologyManager
ShortFormProvider sfp = new ManchesterOWLSyntaxPrefixNameShortFormProvider(
owlManager.getOntologyFormat(owlOntology));
BidirectionalShortFormProvider shortFormProvider = new BidirectionalShortFormProviderAdapter(
ontologies, sfp);
return shortFormProvider;
}
But if I change my String from name max 1 owl:real to name max 1 xsd:string then there is no exception thrown from code. What's the problem ? How to avoid it ?
This is an OWLAPI bug, fixed in the current trunk versions. The fix will be released in 4.2.6 and 5.0.3, once they are completed and published on Maven Central.
Related
How to seperate one RDF model into two models in Jena?
Now I have a RDF data, which contain two resources(I don't know whether it is correct to call the staff in rdf:description a resource), Now I want to separate the two resource into two rdf data in Jena, I do not know how to use the API to do it, The data example: <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:obs="http://localhost/SensorSchema/ontology#" > <rdf:Description rdf:about="http://localhost/SensorSchema/ontology#Observation_51709293_1_104519dd-63dc-4560-9286-8d621ce153c5"> <obs:hasLatitude rdf:datatype="http://www.w3.org/2001/XMLSchema#double">65.00999166666666</obs:hasLatitude> <obs:hasDate rdf:datatype="http://www.w3.org/2001/XMLSchema#long">1365156000000</obs:hasDate> <obs:hasDirection rdf:datatype="http://www.w3.org/2001/XMLSchema#int">212</obs:hasDirection> <obs:hasVelocity rdf:datatype="http://www.w3.org/2001/XMLSchema#double">28.0</obs:hasVelocity> <obs:hasAcceleration rdf:datatype="http://www.w3.org/2001/XMLSchema#double">0.0</obs:hasAcceleration> <obs:hasLongitude rdf:datatype="http://www.w3.org/2001/XMLSchema#double">25.46780833333333</obs:hasLongitude> <obs:hasArea rdf:datatype="http://www.w3.org/2001/XMLSchema#int">38</obs:hasArea> <obs:hasDateTime>2013-04-05T13:00:00</obs:hasDateTime> <obs:hasSender rdf:datatype="http://www.w3.org/2001/XMLSchema#int">51709293</obs:hasSender> <rdf:type rdf:resource="http://localhost/SensorSchema/ontology#Observation"/> <obs:hasID rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</obs:hasID> <obs:hasDistance rdf:datatype="http://www.w3.org/2001/XMLSchema#double">0.0</obs:hasDistance> </rdf:Description> <rdf:Description rdf:about="http://localhost/SensorSchema/ontology#Observation_51709293_1_104519dd-63dc-4560-9286-8d621ce16666"> <obs:hasLatitude rdf:datatype="http://www.w3.org/2001/XMLSchema#double">65.00999166666666</obs:hasLatitude> <obs:hasDate rdf:datatype="http://www.w3.org/2001/XMLSchema#long">1365156000000</obs:hasDate> <obs:hasDirection rdf:datatype="http://www.w3.org/2001/XMLSchema#int">500</obs:hasDirection> <obs:hasVelocity rdf:datatype="http://www.w3.org/2001/XMLSchema#double">28.0</obs:hasVelocity> <obs:hasAcceleration rdf:datatype="http://www.w3.org/2001/XMLSchema#double">0.0</obs:hasAcceleration> <obs:hasLongitude rdf:datatype="http://www.w3.org/2001/XMLSchema#double">25.46780833333333</obs:hasLongitude> <obs:hasArea rdf:datatype="http://www.w3.org/2001/XMLSchema#int">38</obs:hasArea> <obs:hasDateTime>2013-04-05T13:00:00</obs:hasDateTime> <obs:hasSender rdf:datatype="http://www.w3.org/2001/XMLSchema#int">51709293</obs:hasSender> <rdf:type rdf:resource="http://localhost/SensorSchema/ontology#Observation"/> <obs:hasID rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</obs:hasID> <obs:hasDistance rdf:datatype="http://www.w3.org/2001/XMLSchema#double">0.0</obs:hasDistance> </rdf:Description> </rdf:RDF> I try to work like that: ResIterator iter= OriginalModel.listSubjects(); int i=0; while(iter.hasNext()) { Resource subject = iter.next(); Model[i].?? // add the whole resource i++; } but I don't know how to quickly add the resource to another model.
Once you have the subject, you can use listProperties to get a StmtIterator over the triples with that subject, and then you can use Model#add(StmtIterator) to add all those triples to a new Model. public void splitModels() throws IOException { // First, create a model and read the content // into it. You probably already have this part, // but we need it for a working example. Model model = ModelFactory.createDefaultModel(); try (InputStream in = SplitModelExample.class.getResourceAsStream("/example.rdf")) { RDFDataMgr.read(model, in, Lang.RDFXML); } // List the subjects in the model. ResIterator subjects = model.listSubjects(); // For each subject, create another empty model that will // contain the triples of which the subject is the subject. // The #listProperties() method returns a StmtIterator over // those triples, and Model#add(StmtIterator) adds all the // triples to a model. Then we'll print out each submodel // to make sure we're getting what we expect. while (subjects.hasNext()) { Resource subject = subjects.next(); Model subModel = ModelFactory.createDefaultModel(); subModel.add(subject.listProperties()); System.out.println("\n<!-- Submodel for "+subject+". -->"); RDFDataMgr.write(System.out, subModel, Lang.RDFXML); } } <!-- Submodel for http://localhost/SensorSchema/ontology#Observation_51709293_1_104519dd-63dc-4560-9286-8d621ce16666. --> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:j.0="http://localhost/SensorSchema/ontology#"> <j.0:Observation rdf:about="http://localhost/SensorSchema/ontology#Observation_51709293_1_104519dd-63dc-4560-9286-8d621ce16666"> <j.0:hasLongitude rdf:datatype="http://www.w3.org/2001/XMLSchema#double" >25.46780833333333</j.0:hasLongitude> <j.0:hasLatitude rdf:datatype="http://www.w3.org/2001/XMLSchema#double" >65.00999166666666</j.0:hasLatitude> <j.0:hasVelocity rdf:datatype="http://www.w3.org/2001/XMLSchema#double" >28.0</j.0:hasVelocity> <j.0:hasID rdf:datatype="http://www.w3.org/2001/XMLSchema#int" >1</j.0:hasID> <j.0:hasDateTime>2013-04-05T13:00:00</j.0:hasDateTime> <j.0:hasDate rdf:datatype="http://www.w3.org/2001/XMLSchema#long" >1365156000000</j.0:hasDate> <j.0:hasDistance rdf:datatype="http://www.w3.org/2001/XMLSchema#double" >0.0</j.0:hasDistance> <j.0:hasSender rdf:datatype="http://www.w3.org/2001/XMLSchema#int" >51709293</j.0:hasSender> <j.0:hasAcceleration rdf:datatype="http://www.w3.org/2001/XMLSchema#double" >0.0</j.0:hasAcceleration> <j.0:hasArea rdf:datatype="http://www.w3.org/2001/XMLSchema#int" >38</j.0:hasArea> <j.0:hasDirection rdf:datatype="http://www.w3.org/2001/XMLSchema#int" >500</j.0:hasDirection> </j.0:Observation> </rdf:RDF> <!-- Submodel for http://localhost/SensorSchema/ontology#Observation_51709293_1_104519dd-63dc-4560-9286-8d621ce153c5. --> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:j.0="http://localhost/SensorSchema/ontology#"> <j.0:Observation rdf:about="http://localhost/SensorSchema/ontology#Observation_51709293_1_104519dd-63dc-4560-9286-8d621ce153c5"> <j.0:hasLatitude rdf:datatype="http://www.w3.org/2001/XMLSchema#double" >65.00999166666666</j.0:hasLatitude> <j.0:hasDate rdf:datatype="http://www.w3.org/2001/XMLSchema#long" >1365156000000</j.0:hasDate> <j.0:hasDirection rdf:datatype="http://www.w3.org/2001/XMLSchema#int" >212</j.0:hasDirection> <j.0:hasVelocity rdf:datatype="http://www.w3.org/2001/XMLSchema#double" >28.0</j.0:hasVelocity> <j.0:hasAcceleration rdf:datatype="http://www.w3.org/2001/XMLSchema#double" >0.0</j.0:hasAcceleration> <j.0:hasLongitude rdf:datatype="http://www.w3.org/2001/XMLSchema#double" >25.46780833333333</j.0:hasLongitude> <j.0:hasArea rdf:datatype="http://www.w3.org/2001/XMLSchema#int" >38</j.0:hasArea> <j.0:hasDateTime>2013-04-05T13:00:00</j.0:hasDateTime> <j.0:hasSender rdf:datatype="http://www.w3.org/2001/XMLSchema#int" >51709293</j.0:hasSender> <j.0:hasID rdf:datatype="http://www.w3.org/2001/XMLSchema#int" >1</j.0:hasID> <j.0:hasDistance rdf:datatype="http://www.w3.org/2001/XMLSchema#double" >0.0</j.0:hasDistance> </j.0:Observation> </rdf:RDF>
Xml validation with xsl
i have been trying to validate xml through xslt for couple of hours. i have following xsl form for xml validation. every time i try to validate xml, i get following warnings below and empty currencyid attributes in xml are ignored and xml validate although its not. Does anyone has an idea why its ignored and validated ? <xsl:variable name="CurrencyCodeList" select="',AED,AFN,ALL,AMD,ANG,AOA,ARS,AUD,AWG,AZN,BAM,BBD,BDT,BGN,BHD,BIF,BMD,BND,BOB,BOV,BRL,BSD,BTN,BWP,BYR,BZD,CAD,CDF,CHE,CHF,CHW,CLF,CLP,CNY,COP,COU,CRC,CUC,CUP,CVE,CZK,DJF,DKK,DOP,DZD,EEK,EGP,ERN,ETB,EUR,FJD,FKP,GBP,GEL,GHS,GIP,GMD,GNF,GTQ,GWP,GYD,HKD,HNL,HRK,HTG,HUF,IDR,ILS,INR,IQD,IRR,ISK,JMD,JOD,JPY,KES,KGS,KHR,KMF,KPW,KRW,KWD,KYD,KZT,LAK,LBP,LKR,LRD,LSL,LTL,LVL,LYD,MAD,MAD,MDL,MGA,MKD,MMK,MNT,MOP,MRO,MUR,MVR,MWK,MXN,MXV,MYR,MZN,NAD,NGN,NIO,NOK,NPR,NZD,OMR,PAB,PEN,PGK,PHP,PKR,PLN,PYG,QAR,RON,RSD,RUB,RWF,SAR,SBD,SCR,SDG,SEK,SGD,SHP,SLL,SOS,SRD,STD,SVC,SYP,SZL,THB,TJS,TMT,TND,TOP,TRY,TTD,TWD,TZS,UAH,UGX,USD,USN,USS,UYI,UYU,UZS,VEF,VND,VUV,WST,XAF,XAG,XAU,XBA,XBB,XBC,XBD,XCD,XDR,XFU,XOF,XPD,XPF,XPF,XPF,XPT,XTS,XXX,YER,ZAR,ZMK,ZWL,'"/> <xsl:template match="//#currencyID" priority="1008" mode="M0"> <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl" context="//#currencyID"/> <!--ASSERT --> <xsl:choose> <xsl:when test="contains($CurrencyCodeList, concat(',',.,','))"/> <xsl:otherwise> <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" test="contains($CurrencyCodeList, concat(',',.,','))"> <xsl:attribute name="location"> <xsl:apply-templates select="." mode="schematron-select-full-path"/> </xsl:attribute> <svrl:text>Geçersiz currencyID niteliği : '<xsl:text/> <xsl:value-of select="."/> <xsl:text/>'. Geçerli değerler için kod listesine bakınız.</svrl:text> </svrl:failed-assert> </xsl:otherwise> </xsl:choose> <xsl:apply-templates select="*|comment()|processing-instruction()" mode="M0"/> Warning: on line 286 The preceding-sibling axis starting at a namespace node will never select anything Warning: on line 311 The preceding-sibling axis starting at a namespace node will never select anything Warning: on line 407 The child axis starting at an attribute node will never select anything Warning: on line 407 The child axis starting at an attribute node will never select anything Warning: on line 407 The child axis starting at an attribute node will never select anything Warning: on line 436 The child axis starting at an attribute node will never select anything Warning: on line 436 The child axis starting at an attribute node will never select anything Warning: on line 436 EDIT: actually i transformed schematron to xslt in order to test it also in xslt. given was schematron for validating. so actually i have to validate through given schematron files, sample xml and java code for validating. main schematron and other files have more rules and patterns. but i removed most of them for sample code and easily testing. everything is validated successfully except attributes in elements.( e.g currencyId attribute). im using UgliSch (Ugli Schematron Validator) for schematron validation. MainSchematron.xml: <?xml version="1.0" encoding="UTF-8"?> <sch:schema xmlns="http://purl.oclc.org/dsdl/schematron" xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" xmlns:ef="http://www.efatura.gov.tr/envelope-namespace"> <sch:include href="UBL-TR_Codelist.xml#codes"/> <sch:include href="UBL-TR_Common_Schematron.xml#abstracts"/> <sch:ns prefix="cbc" uri="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" /> <sch:rule context="//cbc:CurrencyCode"> <sch:extends rule="GeneralCurrencyCodeCheck"/> </sch:rule> <sch:rule context="//#currencyID"> <sch:extends rule="GeneralCurrencyIDCheck"/> </sch:rule> </sch:schema> UBL-TR_Common_Schematron.xml: <sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns="http://purl.oclc.org/dsdl/schematron"> <sch:pattern name="AbstractRules" id="abstracts"> <sch:p>Pattern for storing abstract rules</sch:p> <!-- Rule to validate currencyID Genel --> <sch:rule abstract="true" id="GeneralCurrencyIDCheck"> <sch:assert test="contains($CurrencyCodeList, concat(',',.,','))">Geçersiz currencyID niteliği : '<sch:value-of select="."/>'. Geçerli değerler için kod listesine bakınız.</sch:assert> </sch:rule> </sch:pattern> </sch:schema> UBL-TR_Codelist.xml: <sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns="http://purl.oclc.org/dsdl/schematron"> <sch:pattern name="CodeList" id="codes"> <sch:let name="CurrencyCodeList" value="',AED,AFN,ALL,AMD,ANG,AOA,ARS,AUD,AWG,AZN,BAM,BBD,BDT,BGN,BHD,BIF,BMD,BND,BOB,BOV,BRL,BSD,BTN,BWP,BYR,BZD,CAD,CDF,CHE,CHF,CHW,CLF,CLP,CNY,COP,COU,CRC,CUC,CUP,CVE,CZK,DJF,DKK,DOP,DZD,EEK,EGP,ERN,ETB,EUR,FJD,FKP,GBP,GEL,GHS,GIP,GMD,GNF,GTQ,GWP,GYD,HKD,HNL,HRK,HTG,HUF,IDR,ILS,INR,IQD,IRR,ISK,JMD,JOD,JPY,KES,KGS,KHR,KMF,KPW,KRW,KWD,KYD,KZT,LAK,LBP,LKR,LRD,LSL,LTL,LVL,LYD,MAD,MAD,MDL,MGA,MKD,MMK,MNT,MOP,MRO,MUR,MVR,MWK,MXN,MXV,MYR,MZN,NAD,NGN,NIO,NOK,NPR,NZD,OMR,PAB,PEN,PGK,PHP,PKR,PLN,PYG,QAR,RON,RSD,RUB,RWF,SAR,SBD,SCR,SDG,SEK,SGD,SHP,SLL,SOS,SRD,STD,SVC,SYP,SZL,THB,TJS,TMT,TND,TOP,TRY,TTD,TWD,TZS,UAH,UGX,USD,USN,USS,UYI,UYU,UZS,VEF,VND,VUV,WST,XAF,XAG,XAU,XBA,XBB,XBC,XBD,XCD,XDR,XFU,XOF,XPD,XPF,XPF,XPF,XPT,XTS,XXX,YER,ZAR,ZMK,ZWL,'"/> </sch:pattern> </sch:schema> sample.xml: <sh:StandardBusinessDocument xsi:schemaLocation="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader PackageProxy_1_2.xsd" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:ef="http://www.efatura.gov.tr/package-namespace" xmlns:oa="http://www.openapplications.org/oagis/9" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ns9="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:ns11="urn:oasis:names:specification:ubl:schema:xsd:ApplicationResponse-2" xmlns:ns3="http://www.hr-xml.org/3" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <sh:StandardBusinessDocumentHeader> <sh:HeaderVersion>1.0</sh:HeaderVersion> <sh:Sender> <sh:Identifier>urn:mail:defaultgb#xxx.com.tr</sh:Identifier> <sh:ContactInformation> <sh:Contact>xxx Kurumsal Bilgi Sistemleri A.Ş</sh:Contact> <sh:ContactTypeIdentifier>UNVAN</sh:ContactTypeIdentifier> </sh:ContactInformation> <sh:ContactInformation> <sh:Contact>8110120507</sh:Contact> <sh:ContactTypeIdentifier>VKN_TCKN</sh:ContactTypeIdentifier> </sh:ContactInformation> </sh:Sender> <sh:Receiver> <sh:Identifier>urn:mail:defaultpk#xxx.com.tr</sh:Identifier> <sh:ContactInformation> <sh:Contact>KAKAR KURUMSAL BİLGİSİSTEMLERİ LTD.ŞTİ. Test Kullanıcısı</sh:Contact> <sh:ContactTypeIdentifier>UNVAN</sh:ContactTypeIdentifier> </sh:ContactInformation> <sh:ContactInformation> <sh:Contact>4545552073</sh:Contact> <sh:ContactTypeIdentifier>VKN_TCKN</sh:ContactTypeIdentifier> </sh:ContactInformation> </sh:Receiver> <sh:DocumentIdentification> <sh:Standard>UBL-TR</sh:Standard> <sh:TypeVersion>1.2</sh:TypeVersion> <sh:InstanceIdentifier>bb583542-a81a-4b45-87d6-e90596101a41</sh:InstanceIdentifier> <sh:Type>SENDERENVELOPE</sh:Type> <sh:MultipleType>false</sh:MultipleType> <sh:CreationDateAndTime>2016-01-06T16:27:25.759+02:00</sh:CreationDateAndTime> </sh:DocumentIdentification> </sh:StandardBusinessDocumentHeader> <ef:Package> <Elements> <ElementType>INVOICE</ElementType> <ElementCount>1</ElementCount> <ElementList> <ns9:Invoice> <ext:UBLExtensions> <ext:UBLExtension> <ext:ExtensionContent> ... </ext:ExtensionContent> </ext:UBLExtension> </ext:UBLExtensions> <cbc:UBLVersionID>2.1</cbc:UBLVersionID> <cbc:CustomizationID>TR1.2</cbc:CustomizationID> <cbc:ProfileID>TICARIFATURA</cbc:ProfileID> <cbc:ID>PAZ2015000000012</cbc:ID> <cbc:CopyIndicator>false</cbc:CopyIndicator> <cbc:UUID>54b0dad2-e3a7-44ee-848a-cf7977000020</cbc:UUID> <cbc:IssueDate>2016-01-06</cbc:IssueDate> <cbc:InvoiceTypeCode>SATIS</cbc:InvoiceTypeCode> <cbc:DocumentCurrencyCode>TRY</cbc:DocumentCurrencyCode> <cbc:LineCountNumeric>0</cbc:LineCountNumeric> <cac:Signature> <cbc:ID schemeID="VKN_TCKN">8110120507</cbc:ID> <cac:SignatoryParty> <cbc:WebsiteURI>http://www.xxx.com.tr/</cbc:WebsiteURI> <cac:PartyIdentification> <cbc:ID schemeID="VKN">8110120507</cbc:ID> </cac:PartyIdentification> <cac:PartyName> <cbc:Name>xxx Kurumsal Bilgi Sistemleri A.Ş</cbc:Name> </cac:PartyName> <cac:PostalAddress> <cbc:StreetName>Besiktas Teknik Universitesi</cbc:StreetName> <cbc:BuildingNumber>150/1G</cbc:BuildingNumber> <cbc:CitySubdivisionName>Besıktas</cbc:CitySubdivisionName> <cbc:CityName>Istanbul</cbc:CityName> <cbc:PostalZone>06100</cbc:PostalZone> <cac:Country> <cbc:Name>Turkiye</cbc:Name> </cac:Country> </cac:PostalAddress> </cac:SignatoryParty> <cac:DigitalSignatureAttachment> <cac:ExternalReference> <cbc:URI>#Signature</cbc:URI> </cac:ExternalReference> </cac:DigitalSignatureAttachment> </cac:Signature> <cac:AccountingSupplierParty> <cac:Party> <cac:PartyIdentification> <cbc:ID schemeID="VKN">7221130507</cbc:ID> </cac:PartyIdentification> <cac:PartyName> <cbc:Name>KAKAR KURUMSAL LTD.ŞTİ.</cbc:Name> </cac:PartyName> <cac:PostalAddress> <cbc:Room/> <cbc:BuildingName/> <cbc:BuildingNumber/> <cbc:CitySubdivisionName>besiktas</cbc:CitySubdivisionName> <cbc:CityName>istanbul</cbc:CityName> <cbc:PostalZone/> <cac:Country> <cbc:Name>ALMANYA</cbc:Name> </cac:Country> </cac:PostalAddress> <cac:Contact> <cbc:Telephone/> <cbc:Telefax/> <cbc:ElectronicMail/> </cac:Contact> </cac:Party> </cac:AccountingSupplierParty> <cac:AccountingCustomerParty> <cac:Party> <cbc:WebsiteURI/> <cac:PartyIdentification> <cbc:ID schemeID="VKN">2535552073</cbc:ID> </cac:PartyIdentification> <cac:PartyName> <cbc:Name>KAKAR LTD.ŞTİ. Test Kullanıcısı</cbc:Name> </cac:PartyName> <cac:PostalAddress> <cbc:ID/> <cbc:Postbox/> <cbc:Room/> <cbc:StreetName/> <cbc:BlockName/> <cbc:BuildingName/> <cbc:BuildingNumber/> <cbc:CitySubdivisionName>besiktas</cbc:CitySubdivisionName> <cbc:CityName>istanbul</cbc:CityName> <cbc:PostalZone/> <cbc:Region/> <cbc:District/> <cac:Country> <cbc:Name>TÜRKİYE</cbc:Name> </cac:Country> </cac:PostalAddress> <cac:Contact> <cbc:Telephone/> <cbc:Telefax/> <cbc:ElectronicMail/> </cac:Contact> <cac:Person> <cbc:FirstName/> <cbc:FamilyName/> </cac:Person> </cac:Party> </cac:AccountingCustomerParty> <cac:TaxTotal> <cbc:TaxAmount currencyID="TRY">2.16</cbc:TaxAmount> <cac:TaxSubtotal> <cbc:TaxableAmount currencyID="asdasdasdasd">0</cbc:TaxableAmount> <cbc:TaxAmount currencyID="TRY">2.16</cbc:TaxAmount> <cbc:CalculationSequenceNumeric>0</cbc:CalculationSequenceNumeric> <cbc:Percent>18</cbc:Percent> <cac:TaxCategory> <cac:TaxScheme> <cbc:Name>KDV</cbc:Name> <cbc:TaxTypeCode>0015</cbc:TaxTypeCode> </cac:TaxScheme> </cac:TaxCategory> </cac:TaxSubtotal> </cac:TaxTotal> <cac:LegalMonetaryTotal> <cbc:LineExtensionAmount currencyID="TRY">12</cbc:LineExtensionAmount> <cbc:TaxExclusiveAmount currencyID="TRY">12</cbc:TaxExclusiveAmount> <cbc:TaxInclusiveAmount currencyID="TRY">14.16</cbc:TaxInclusiveAmount> <cbc:AllowanceTotalAmount currencyID="TRY">0</cbc:AllowanceTotalAmount> <cbc:PayableAmount currencyID="TRY">14.16</cbc:PayableAmount> </cac:LegalMonetaryTotal> <cac:InvoiceLine> <cbc:ID>1</cbc:ID> <cbc:InvoicedQuantity unitCode="NIU">1</cbc:InvoicedQuantity> <cbc:LineExtensionAmount currencyID="">12</cbc:LineExtensionAmount> <cac:AllowanceCharge> <cbc:ChargeIndicator>false</cbc:ChargeIndicator> <cbc:MultiplierFactorNumeric>0</cbc:MultiplierFactorNumeric> <cbc:Amount currencyID="">0</cbc:Amount> <cbc:BaseAmount currencyID="">0</cbc:BaseAmount> </cac:AllowanceCharge> <cac:TaxTotal> <cbc:TaxAmount currencyID="">2.16</cbc:TaxAmount> <cac:TaxSubtotal> <cbc:TaxableAmount currencyID="">0</cbc:TaxableAmount> <cbc:TaxAmount currencyID="">2.16</cbc:TaxAmount> <cbc:Percent>18</cbc:Percent> <cac:TaxCategory> <cac:TaxScheme> <cbc:Name>KDV</cbc:Name> <cbc:TaxTypeCode>0015</cbc:TaxTypeCode> </cac:TaxScheme> </cac:TaxCategory> </cac:TaxSubtotal> </cac:TaxTotal> <cac:Item> <cbc:Name>asdasd</cbc:Name> </cac:Item> <cac:Price> <cbc:PriceAmount currencyID="TRY">12</cbc:PriceAmount> </cac:Price> </cac:InvoiceLine> </ns9:Invoice> </ElementList> </Elements> </ef:Package> </sh:StandardBusinessDocument> java : try (InputStream ubl = getClass().getResourceAsStream("/schematrons/UBL-TR_Main_Schematron.xml");) { SchemaFactory schemaFactory = SchemaFactory.newInstance(XmlSchemaNsUris.SCHEMATRON_NS_URI); Schema schema = schemaFactory.newSchema(new StreamSource(ubl)); Validator validator = schema.newValidator(); validator.setErrorHandler(validationErrorHandler); validator.validate(new StringSource(new String(binary,"UTF-8"))); } catch (Exception e) { e.printStackTrace(); }
Reading RDF data using Jena failing
The following code is to read a schema and a data file to find rdf.type of colin and Person. However, I am getting the error: Exception in thread "main" org.apache.jena.riot.RiotException: [line: 1, col: 1 ] Content is not allowed in prolog. The code is given below: public void reason(){ String NS = "urn:x-hp:eg/"; String fnameschema = "D://Work//EclipseWorkspace//Jena//data//rdfsDemoSchema.rdf"; String fnameinstance = "D://Work//EclipseWorkspace//Jena//data//rdfsDemoData.rdf"; Model schema = FileManager.get().loadModel(fnameschema); Model data = FileManager.get().loadModel(fnameinstance); InfModel infmodel = ModelFactory.createRDFSModel(schema, data); Resource colin = infmodel.getResource(NS+"colin"); System.out.println("Colin has types"); for (StmtIterator i = infmodel.listStatements(colin, RDF.type, (RDFNode)null); i.hasNext(); ) { Statement s = i.nextStatement(); System.out.println(s); } Resource Person = infmodel.getResource(NS+"Person"); System.out.println("\nPerson has types:"); for (StmtIterator i = infmodel.listStatements(Person, RDF.type, (RDFNode)null); i.hasNext(); ) { Statement s = i.nextStatement(); System.out.println(s); } } The file rdfsDemoData.rdf #prefix eg: <urn:x-hp:eg/> . <Teenager rdf:about="⪚colin"> <mum rdf:resource="⪚rosy" /> <age>13</age> </Teenager> The file rdfsDemoSchema.rdf #prefix eg: <urn:x-hp:eg/> . <rdf:Description rdf:about="⪚mum"> <rdfs:subPropertyOf rdf:resource="⪚parent"/> </rdf:Description> <rdf:Description rdf:about="⪚parent"> <rdfs:range rdf:resource="⪚Person"/> <rdfs:domain rdf:resource="⪚Person"/> </rdf:Description> <rdf:Description rdf:about="⪚age"> <rdfs:range rdf:resource="&xsd;integer" /> </rdf:Description>
Your data is bad syntax. You are mixing Turtle and RDF/XML. RDF/XML does nto have #prefix - it uses XML's namespaces. It looks like you want an XML entity declaration like: <?xml version="1.0"?> <!DOCTYPE rdf:RDF [ <!ENTITY eg "urn:x-hp:eg/" > ]> ...
Get Property Value Intersection of two objects in an ontology using OWL API
I am new to OWL API and trying to experiment with it. I have created a simple ontology in protege and reciprocal application in eclipse using OWL API. Ontology structure is as follows:- ---------------------------------------------------------------------------------------- Class Object (Data Property)StringValue ObjectProperty relatedTo ---------------------------------------------------------------------------------------- WordString WS1 "One" DS1 WS2 "Two" DS2 WS3 "Three" DS3 DigiString DS1 "1" DS2 "2" DS3 "3" ---------------------------------------------------------------------------- Complete ontology is as follows:- <rdf:RDF xmlns="http://localhost:3030/DigiWord.owl#" xml:base="http://localhost:3030/DigiWord.owl" xmlns:DigiWord="http://localhost:3030/DigiWord.owl#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 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#"> <owl:Ontology rdf:about="http://localhost:3030/DigiWord.owl"/> <!-- // Object Properties /////////////////////////////////////////////////////////////////////////////////////// --> <!-- http://localhost:3030/DigiWord.owl#relatedTo --> <owl:ObjectProperty rdf:about="&DigiWord;relatedTo"> <rdfs:domain rdf:resource="&DigiWord;DigiString"/> <rdfs:range rdf:resource="&DigiWord;WordString"/> </owl:ObjectProperty> <!-- // // Data properties /////////////////////////////////////////////////////////////////////////////////////// --> <!-- http://localhost:3030/DigiWord.owl#stringValue --> <owl:DatatypeProperty rdf:about="&DigiWord;stringValue"> <rdfs:domain rdf:resource="&DigiWord;DigiString"/> <rdfs:domain rdf:resource="&DigiWord;WordString"/> <rdfs:range rdf:resource="&xsd;string"/> </owl:DatatypeProperty> <!-- // Classes /////////////////////////////////////////////////////////////////////////////////////// --> <!-- http://localhost:3030/DigiWord.owl#DigiString --> <owl:Class rdf:about="&DigiWord;DigiString"/> <!-- http://localhost:3030/DigiWord.owl#WordString --> <owl:Class rdf:about="&DigiWord;WordString"/> <!-- // Individuals /////////////////////////////////////////////////////////////////////////////////////// --> <!-- http://localhost:3030/DigiWord.owl#DS1 --> <owl:NamedIndividual rdf:about="&DigiWord;DS1"> <rdf:type rdf:resource="&DigiWord;DigiString"/> <stringValue rdf:datatype="&xsd;string">1</stringValue> <relatedTo rdf:resource="&DigiWord;WS1"/> </owl:NamedIndividual> <!-- http://localhost:3030/DigiWord.owl#DS2 --> <owl:NamedIndividual rdf:about="&DigiWord;DS2"> <rdf:type rdf:resource="&DigiWord;DigiString"/> <stringValue rdf:datatype="&xsd;string">2</stringValue> <relatedTo rdf:resource="&DigiWord;WS2"/> </owl:NamedIndividual> <!-- http://localhost:3030/DigiWord.owl#DS3 --> <owl:NamedIndividual rdf:about="&DigiWord;DS3"> <rdf:type rdf:resource="&DigiWord;DigiString"/> <stringValue rdf:datatype="&xsd;string"></stringValue> <relatedTo rdf:resource="&DigiWord;WS3"/> </owl:NamedIndividual> <!-- http://localhost:3030/DigiWord.owl#WS1 --> <owl:NamedIndividual rdf:about="&DigiWord;WS1"> <rdf:type rdf:resource="&DigiWord;WordString"/> <stringValue rdf:datatype="&xsd;string">One</stringValue> </owl:NamedIndividual> <!-- http://localhost:3030/DigiWord.owl#WS2 --> <owl:NamedIndividual rdf:about="&DigiWord;WS2"> <rdf:type rdf:resource="&DigiWord;WordString"/> <stringValue rdf:datatype="&xsd;string">Two</stringValue> </owl:NamedIndividual> <!-- http://localhost:3030/DigiWord.owl#WS3 --> <owl:NamedIndividual rdf:about="&DigiWord;WS3"> <rdf:type rdf:resource="&DigiWord;WordString"/> <stringValue rdf:datatype="&xsd;string">Three</stringValue> </owl:NamedIndividual> </rdf:RDF> I want to retrieve Object WS1 for DS1, WS2 for DS2 i.e upon providing strings "1", "2" etc my code should retrieve "One" , "Two" respectively. I have not come across any relevant code of this type on net.Any help would be appreciated. Thanks in Advance.
The following example (OWLAPI 4) should help: OWLOntology o = ... your ontology here String ns = "http://localhost:3030/DigiWord.owl#"; OWLDataFactory df = o.getOWLOntologyManager().getOWLDataFactory(); OWLObjectProperty relatedto = df.getOWLObjectProperty(IRI.create(ns + "relatedTo")); OWLDataProperty stringValue = df.getOWLDataProperty(IRI.create(ns + "stringValue")); SimpleRenderer renderer = new SimpleRenderer(); for (OWLNamedIndividual i : o.getIndividualsInSignature()) { for (OWLLiteral lit : EntitySearcher.getDataPropertyValues(i, stringValue, o)) { System.out.println(i + " has values " + renderer.render(lit)); } for (OWLIndividual related : EntitySearcher.getObjectPropertyValues(i, relatedto, o)) { for (OWLLiteral lit : EntitySearcher.getDataPropertyValues(related, stringValue, o)) { System.out.println(i + " related to " + related + " which has values " + renderer.render(lit)); } } } Edit: to find matches for your query: for (OWLNamedIndividual i : o.getIndividualsInSignature()) { for (OWLIndividual related : EntitySearcher.getObjectPropertyValues(i, relatedto, o)) { for (OWLLiteral lit : EntitySearcher.getDataPropertyValues(related, stringValue, o)) { if(lit.getLexicalForm().equals("1")){ for (OWLLiteral lit : EntitySearcher.getDataPropertyValues(i, stringValue, o)) { System.out.println(i + " has values " + renderer.render(lit)); } } } } }
Cutting a XML with JAXB
I have the following xml: <Package> <PackageHeader> <name>External Vendor File</name> <description>External vendor file for some purpose</description> <version>3.141694baR3</version> </PackageHeader> <PackageBody> <Characteristic id="1"> <Size> <value>1.68</value> <scale>Meters</scale> <comment>Size can vary, depending on temperature</comment> </Size> <Weight> <value>9</value> <scale>M*Tons</scale> <comment>His mama is so fat, we had to use another scale</comment> </Weight> <rating> <ratingCompany>ISO</ratingCompany> <rating:details xmlns:rating="http://www.w3schools.com/ratingDetails"> <rating:value companyDepartment="Finance">A</rating:value> <rating:expirationDate update="1/12/2010">1/1/2014</rating:expirationDate> <rating:comment userID="z94234">You're not Silvia.</rating:comment> <rating:comment userID="r24942">You're one of the Kung-Fu Creatures On The Rampage</rating:comment> <rating:comment userID="i77880">TWO!</rating:comment> <rating:priority>3</rating:priority> </rating:details> </rating> </Characteristic> <Characteristic id="2"> <Size/> <Weight/> <rating/> </Characteristic> ... <Characteristic id="n"/> </PackageBody> </Package> And the following Java code: public class XMLTest { public static void main(String[] args) throws Exception { Package currentPackage = new Package(); Package sourcePackage = new Package(); int totalCharacteristics; PackageBody currentPackageBody = new PackageBody(); Characteristic currentCharacteristic = new Characteristic(); rating currentRating = new rating(); FileInputStream fis = new FileInputStream("sourceFile.xml"); JAXBContext myCurrentContext = JAXBContext.newInstance(Package.class); Marshaller m = myCurrentContext.createMarshaller(); Unmarshaller um = myCurrentContext.createUnmarshaller(); sourcePackage = (Package)um.unmarshal(fis); currentPackage.setPackageHeader(sourcePackage.getPackageHeader()); totalCharacteristics = sourcePackage.getPackageBody().getCharacteristics().size(); for (int i = 0; i < totalCharacteristics; i++) { currentRating = sourcePackage.getPackageBody().getCharacteristics().get(i).getrating(); } currentCharacteristic.setrating(currentRating); currentPackageBody.getCharacteristics().add(currentCharacteristic); currentPackage.setPackageBody(currentPackageBody); m.marshal(currentPackage, new File("targetFile.xml")); fis.close(); } } Which gives me the next XML: <Package> <PackageHeader> <name>External Vendor File</name> <description>External vendor file for some purpose</description> <version>3.141694baR3</version> </PackageHeader> <PackageBody> <Characteristic id="1"> <rating> <ratingCompany>ISO</ratingCompany> <rating:details xmlns:rating="http://www.w3schools.com/ratingDetails"> <rating:value companyDepartment="Finance">A</rating:value> <rating:expirationDate update="1/12/2010">1/1/2014</rating:expirationDate> <rating:comment userID="z94234">You're not Silvia.</rating:comment> <rating:comment userID="r24942">You're one of the Kung-Fu Creatures On The Rampage</rating:comment> <rating:comment userID="i77880">TWO!</rating:comment> <rating:priority>3</rating:priority> </rating:details> </rating> </Characteristic> <Characteristic id="2"> <rating/> </Characteristic> ... <Characteristic id="n"/> </PackageBody> </Package> And this is what I need: <Package> <PackageHeader> <name>External Vendor File</name> <description>External vendor file for some purpose</description> <version>3.141694baR3</version> </PackageHeader> <PackageBody> <Characteristic> <rating id="1"> <ratingCompany>ISO</ratingCompany> <rating:details xmlns:rating="http://www.w3schools.com/ratingDetails"> <rating:comment userID="z94234">You're not Silvia.</rating:comment> <rating:comment userID="r24942">You're one of the Kung-Fu Creatures On The Rampage</rating:comment> <rating:comment userID="i77880">TWO!</rating:comment> <rating:priority>3</rating:priority> </rating:details> </rating> </Characteristic> <Characteristic> <rating id="2"/> </Characteristic> ... <Characteristic/> </PackageBody> </Package> But I have a few questions: How could I implement a way to read a 4GBs file? (for example, reading it with StAX). If I want to filter some tags from source to target(as in the last xml), would I have to assign them one by one to the targetFile? Is there any iterator that might allow me to go through all subnodes and assign them? If the sourceFile changes, would I need to rerun the xjc and recompile the whole project? Thanks.
For reading huge XML files, you definitely need a streaming parser like StAX. In addition, you can use a combination of JAXB to selectively map a given piece of xml to java object if you wish work with it. You need to regenerate your JAXB classes only if your schema changes. No need to regenerate if you application code changes.