How to read ontology file with owl:imports in JENA? - jena

I have an owl file that import some other ontologies from other owl files. I tried to follow JENA API Documentation to deal with it, but could not succeed. What am I missing?
The codes I used are above:
e-GovSecAOnto.owl imports:
<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://www.ida.liu.se/~iislab/projects/secont/Security.owl"/>
<owl:imports rdf:resource="http://www.unifiedcloud.org/2009/2/26/uci.owl"/>
<owl:imports rdf:resource="http://wwwsemanticweb.org/ontologies/Portaria141.owl"/>
</owl:Ontology>
ont-policy.rdf:
<?xml version='1.0'?>
<!DOCTYPE rdf:RDF [
<!ENTITY jena 'http://jena.hpl.hp.com/schemas/'>
<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>
<!ENTITY base '&jena;2003/03/ont-manager'>
<!ENTITY ont '&base;#'>
]>
<rdf:RDF
xmlns:rdf ="&rdf;"
xmlns:rdfs="&rdfs;"
xmlns ="&ont;"
xml:base ="&base;"
>
<DocumentManagerPolicy>
<processImports rdf:datatype="&xsd;boolean">true</processImports>
<cacheModels rdf:datatype="&xsd;boolean">true</cacheModels>
</DocumentManagerPolicy>
<OntologySpec>
<altURL rdf:resource="file:///C:/Users/usuario/Documents/Visual Studio 2013/WebSites/FrameworkBeta/Repository/Ontologies/Portaria141/Portaria141_V1.owl"/>
<language rdf:resource="http://www.w3.org/2002/07/owl"/>
<publicURI rdf:resource="http://wwwsemanticweb.org/ontologies/Portaria141.owl"/>
</OntologySpec>
<OntologySpec>
<altURL rdf:resource="file:///C:/Users/usuario/Documents/Visual Studio 2013/WebSites/FrameworkBeta/Repository/Ontologies/CloudComputing/uci.owl"/>
<language rdf:resource="http://www.w3.org/2002/07/owl"/>
<publicURI rdf:resource="http://www.unifiedcloud.org/2009/2/26/uci.owl"/>
</OntologySpec>
</rdf:RDF>
ReadOntology():
OntDocumentManager dm = new OntDocumentManager(dmFileName);
OntModelSpec modelSpec = new OntModelSpec( OntModelSpec.RDFS_MEM );
modelSpec.setDocumentManager(dm);
OntModel m = ModelFactory.createOntologyModel(modelSpec);
m.read(FileManager.get().open(#"C:\Users\usuario\Documents\Visual Studio 2013\WebSites\FrameworkBeta\Repository\Ontologies\e-GovSecAOnto\e-GovSecAOnto.owl"), NS);

Related

Unable to generate correct namespace in generated xml

I am getting some extra lines in the namespace for the xml file generated by SAP BODS using the xsd file.
The below is my main xsd-
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns = "http://www.demandware.com/xml/impex/customer/2006-10-31"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
targetNamespace = "http://www.demandware.com/xml/impex/customer/2006-10-31"
elementFormDefault = "qualified">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd" />
The xml xsd is below-
<?xml version='1.0'?>
<!-- DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "XMLSchema.dtd" -->
<xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xml:lang="en">
The resulting xml top lines that i am seeing are -
<?xml version="1.0" encoding = "UTF-8" ?>
<!-- SAP Data Services generated XML -->
<!-- 2020-04-27.13:27:20(128,601)[1] -->
<ns1:customers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns1="http://www.demandware.com/xml/impex/customer/2006-10-31"
xmlns:ns2="http://www.w3.org/XML/1998/namespace"
My expected result is -
<?xml version="1.0" encoding="UTF-8"?>
<customers xmlns="http://www.demandware.com/xml/impex/customer/2006-10-31">
Can anyone please help.

attaching #Entity annotations to jaxb-generated classes from a wsdl

My goal is to add #Entity annotations to the classes that are generated from a wsdl. I'm using cxf-codegen-plugin's wsdl2java goal, and pointing at a local wsdl file. I can generate all the sources without any problem, but when I try to add a binding file, I'm running into problems.
Here's a segment of the wsdl (the file is CAAudit.wsdl and is in my resources directory):
<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions targetNamespace="http://www.ocse.gov/quick/wsdl/CAAudit.wsdl"
xmlns:audw="http://www.ocse.gov/quick/wsdl/CAAudit.wsdl"
xmlns:audx="http://www.ocse.gov/quick/wsdl/CAAudit.xsd"
xmlns:qikrsp="urn:us:gov:hhs:acf:qikrsp"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
name="CAAudit"
>
<wsdl:types>
<xsd:schema targetNamespace="http://www.ocse.gov/quick/wsdl/CAAudit.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<xsd:import namespace="urn:us:gov:hhs:acf:qikrsp"
schemaLocation="QuickResponse.xsd" />
<xsd:complexType name="NotifyCAAuditRequest" >
<xsd:sequence>
<xsd:element ref="qikrsp:QuickResponse" />
</xsd:sequence>
</xsd:complexType>
....
My first question is I'm really not certain what should go in the binding file. First, I'm pretty sure that I need jaxws bindings to work with the wsdl (the jaxb binding only has the schemaLocation attribute), although I don't need to generate web service classes.
Next, I'm not sure I'm not sure if the introduction of a new xmlns in the schema element will cause problems for an xpath search. I did have problems running it with notepad++'s xpath evaluation.
Also, I'm not sure if the fact that the QuickResponse element (which is the class I want to annotate) is defined by a reference is hindering my efforts. I'm not sure if or how (or where) I would include the referenced xsd file.
Here is one possible binding file (I was just trying to get an #Generated on the class to start with):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="annox"
jaxb:version="2.1"
>
<jaxws:bindings wsdlLocation="CAAudit.wsdl"
node="/wsdl:definitions/wsdl:types">
<jaxb:bindings node=".//xsd:schema">
<annox:annotate>#javax.annotation.Generated({"JAXWS"})</annox:annotate>
</jaxb:bindings>
</jaxws:bindings>
</jaxb:bindings>
I did not manage to customize schema embedded in WSDL. This are my latest efforts:
https://github.com/highsource/jaxb2-annotate-plugin/blob/master/tests/jaxws/src/main/resources/wsdl-bindings.xjb
What works with WSDLs is attaching customizations via SCD. But SCD does not allow proprietary customization elements (like annotate:*). So that won't help with jaxb2-annotate-plugin.
So the only thing which would probably work is to extract schema from the WSDL into an own file.

How to translate RDF graphs properties into OWL object properties?

I need to convert my RDF graph document into OWL (1 or 2) recognized by Protege 3.x. There is a W3C Recommendation for mapping OWL 2 Web Ontology Language Mapping to RDF Graphs which says that to declare Object Properties from RDF graphs one should add the rdf:type owl:ObjectProperty element. I have found problems for expressing OWL object properties with RDF graph formalisms in the following code:
<rdf:Property rdf:about="&uni;isTaughtBy">
<rdf:type rdf:resource="&owl;ObjectProperty"/>
<rdfs:domain rdf:resource="&uni;Course"/>
<rdfs:range rdf:resource="&uni;Proffessor"/>
</rdf:Property>
With the following specified namespaces:
xmlns:uni="http://www.mydomain.org/uni-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
Unfortunately, the upper mentioned code is not recognized and thus shown in the Protege 3.x IDE.
The following code is readable by Protege 4 (recommended version). Copy paste the block and save it in a new file, you should then be able to read it with Protege:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY uni-ns "http://www.mydomain.org/uni-ns#" >
<!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.mydomain.org/uni-ns#"
xml:base="http://www.mydomain.org/uni-ns"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:uni-ns="http://www.mydomain.org/uni-ns#"
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://www.mydomain.org/uni-ns#"/>
<owl:ObjectProperty rdf:about="&uni-ns;isTaughtBy">
<rdfs:domain rdf:resource="&uni-ns;Course"/>
<rdfs:range rdf:resource="&uni-ns;Professor"/>
</owl:ObjectProperty>
<owl:Class rdf:about="&uni-ns;Course"/>
<owl:Class rdf:about="&uni-ns;Professor">
<rdfs:subClassOf rdf:resource="&owl;Thing"/>
</owl:Class>
</rdf:RDF>

Parsing with SAX and handling character entities

I am parsing a MathML expression with SAX (although the fact that it's MathML may not be completely relevant). An example input string is
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mrow>
<mo>λ</mo>
</mrow>
</math>
In order for the SAX parser to accept this string, I expand it a bit:
<?xml version="1.0"?>
<!DOCTYPE doc_type [
<!ENTITY nbsp " ">
<!ENTITY amp "&">
]>
<body>
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mrow>
<mo>λ</mo>
<mrow>
</math>
</body>
Now, when I run the SAX parser on this, I get an exception:
[Fatal Error] :5:86: The entity "lambda" was referenced, but not declared.
org.xml.sax.SAXParseException: The entity "lambda" was referenced, but not
declared.
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
However, I know how to fix that. I simply add this line to the string being parsed:
<!ENTITY lambda "Λ">
This gives me
<?xml version="1.0"?>
<!DOCTYPE doc_type [
<!ENTITY nbsp " ">
<!ENTITY amp "&">
<!ENTITY lambda "Λ">
]>
<body>
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mrow>
<mo>λ</mo>
<mrow>
</math>
</body>
Now, it parses just fine, thank you.
However, the problem is that I can't add an ENTITY declaration for every possible character entity that might be used in MathML (for example, "part", "notin", and "sum").
How do I rewrite this string so that it can be parsed for any possible character entity that might be included?
Use a DOCTYPE declaration that refers to the MathML DTD:
<!DOCTYPE math
PUBLIC "-//W3C//DTD MathML 3.0//EN"
"http://www.w3.org/Math/DTD/mathml3/mathml3.dtd">
or a local copy of the same.

Delphi 2007 isn't generating the XML I want to send to my Java-WS web service

I have a Java web service to which I've linked from a Delphi 2007 app using the WSDL Importer. Setting it up has been a rocky road but I'm almost there!
I now have the situation where my arrays aren't being serialized in a way that my Java web service can consume. I've written the same app in .Net to test it out (it works fine) and the XML I'm looking to generate looks like this: -
<?xml version="1.0"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body xmlns:NS2="http://path.to.service">
<NS1:addActivities xmlns:NS1="http://path.to.service/">
<login href="#1"/>
<project xsi:type="xsd:string">PROJ001</project>
<activities>
<id xsi:type="xsd:string">DELPHITEST</id>
<name xsi:type="xsd:string">This is a test</name>
</activities>
<activities>
<id xsi:type="xsd:string">DELPHITEST2</id>
<name xsi:type="xsd:string">This is another test</name>
</activities>
</NS1:addActivities>
<NS2:login id="1" xsi:type="NS2:login">
<database xsi:type="xsd:string">My_database</database>
<password xsi:type="xsd:string">neverUmind</password>
<username xsi:type="xsd:string">bob</username>
</NS2:login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
However, the XML that Delphi generates is as follows: -
<?xml version="1.0"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body xmlns:NS2="http://path.to.service/">
<NS1:addActivities xmlns:NS1="http://path.to.service/">
<login href="#1"/>
<project xsi:type="xsd:string">PROJ001</project>
<activities xsi:type="SOAP-ENC:Array"
SOAP-ENC:arrayType="NS2:activity[2]">
<item href="#2"/>
<item href="#3"/>
</activities>
</NS1:addActivities>
<NS2:login id="1" xsi:type="NS2:login">
<database xsi:type="xsd:string">My_database</database>
<password xsi:type="xsd:string">neverUmind</password>
<username xsi:type="xsd:string">bob</username>
</NS2:login>
<NS2:activity id="2" xsi:type="NS2:activity">
<id xsi:type="xsd:string">DELPHITEST</id>
<name xsi:type="xsd:string">This is a test</name>
</NS2:activity>
<NS2:activity id="3" xsi:type="NS2:activity">
<id xsi:type="xsd:string">DELPHITEST2</id>
<name xsi:type="xsd:string">This is another test</name>
</NS2:activity>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Basically, I need Delphi to stop creating activity elements within the activities element and instead just put each ID and Name inside the an activities element (as .Net does and Java seems to expect).
I've buggered about with the InvRegistry.RegisterInvokeOptions and the RemClassRegistry.RegisterSerializeOptions but none of the combinations seem to work. To be honest I'm on the verge of writting my own XML parser for this as it's taking way to long to figure out. However, if anyone has any suggestions on how this should work I'd be very grateful.
Surely somebody out there must have consumed a Java-WS web service via Delphi 2007 before :)
TIA
It seems the XMLDocument component in Delphi 2007 is broken. I've installed the Alcinoe component instead and that works a charm. That was only a week wasted ... grrrr

Resources