<!-- http://www.semanticweb.org/vaio/ontologies/2013/0/untitled-ontology-113#hasDegree -->
<owl:ObjectProperty rdf:about="http://www.semanticweb.org/vaio/ontologies/2013/0/untitled-ontology-113#hasDegree">
<rdfs:range rdf:resource="http://www.semanticweb.org/vaio/ontologies/2013/0/untitled-ontology-113#degree"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/vaio/ontologies/2013/0/untitled-ontology-113#student"/>
</owl:ObjectProperty>
Using java api i need to check in <owl:ObjectProperty ,
if rdf:about then how I take hasDegree after the # and also .. similarly if rdfs:range then degree after #
on the 6th line?
Or how can i extract these value using java api?
I'm not entirely sure what you're trying to get out of the file, your question is not clear. But if you want to parse OWL, particularly OWL in RDF/XML format as you've shown, you should look at using either Jena or Sesame as they are the defacto standard Java APIs for working with RDF. I would recommend the Sesame API because it's simpler and easier to get the hang of, but both are very good libraries.
Each have good documentation on the website on how to use the API and active user & developer forums where you can seek help.
Good luck.
Since your input is in OWL, consider using the OWL-API, or any other OWL API, rather than a less OWL-specific tool like XPath, XSLT, an RDF library, etc.
I am assuming you are using the OWL-API and that your questions is: "How do I get the ranges or domains of an object property in my ontology?" In that case:
/*Load the ontology from a local file and do the initialisations*/
File inputfile = new File("ontologyPath");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); ;
OWLDataFactory dataFactory = manager.getOWLDataFactory();
OWLOntology yourOntology = manager.loadOntologyFromOntologyDocument(inputfile);
IRI ontologyIRI = yourOntology.getOntologyID().getOntologyIRI();
/*Get an object property and its ranges*/
OWLObjectProperty o_p_about = dataFactory.getOWLObjectProperty(IRI.create(ontologyIRI + "#"+"about"));
Set<OWLClassExpression> ranges_of_about = about.getRanges(LUCADAOntology);
To pick it up from here, you can check the documentation and example codes on the OWL-API webpage, they are very usfeul.
Use Jena API to call the OWL file,then Turtle to write/output it.
Related
I am trying to read a specific property using Apache POI, my aim is to change its value and save the file in a different location. The issue is that the property in question is not a core, custom or extended one...Its format as shown by Apache Tika is:
<meta name="meta:just-a-name" content="165" />
I have read that with the HPSF API it was possible to read every kind of property in Property Sets, but since my file is a newer version, I cannot use it.
With a custom property I was able to do:
POIXMLProperties properties = document.getProperties();
CTProperty aProperty = properties.getCustomProperties().getProperty("Custom_prop");
aProperty.setI4(12);
properties.commit();
document.write(out);
Do you know how I can do the same thing with the non-standard property?
I am new in the semantic web field, and i'm trying to create a java model using JENA to extract classes, subclass and/or comments from an OWL file..
any help/guidance on how to do such thing would be appreciated.
Thank you
You can do so with the Jena Ontology API. This API allows you to create an ontology model from owl file and then provides you access to all the information stored in the ontology as Java Classes.
Here is a quick introduction to Jena ontology. This introduction contains useful information on getting started with Jena Ontology.
The code generally looks like this:
String owlFile = "path_to_owl_file"; // the file can be on RDF or TTL format
/* We create the OntModel and specify what kind of reasoner we want to use
Depending on the reasoner you can acces different kind of information, so please read the introduction. */
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
/* Now we read the ontology file
The second parameter is the ontology base uri.
The third parameter can be TTL or N3 it represents the file format*/
model.read(owlFile, null, "RDF/XML");
/* Then you can acces the information using the OntModel methods
Let's access the ontology properties */
System.out.println("Listing the properties");
model.listOntProperties().forEachRemaining(System.out::println);
// let's access the classes local names and their subclasses
try {
base.listClasses().toSet().forEach(c -> {
System.out.println(c.getLocalName());
System.out.println("Listing subclasses of " + c.getLocalName());
c.listSubClasses().forEachRemaining(System.out::println);
});
} catch (Exception e) {
e.printStackTrace();
}
// Note that depending on the classes types, accessing some information might throw an exception.
Here is the Jena Ontology API JavaDoc.
I hope it was useful!
I have been trying endlessly to parse the Experimental Factor Ontology (EFO) file, but I am not able to parse it. The file I have opens fine in Protege, but I cannot seem to get it to load in Java. I have looked at a few sets of example code, and I am copying them seemingly exactly, but I do not understand why parsing fails. Here is my code:
System.setProperty("entityExpansionLimit","100000000");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
URI uri = URI.create("file:~/efo.owl");
IRI iri = IRI.create(uri);
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(iri);
And here are the errors I get:
Could not load ontology: Problem parsing
file:/~/efo.owl
Could not parse ontology. Either a suitable parser could not be found, or
parsing failed. See parser logs below for explanation.
The following parsers were tried:
Thank you, I know some similar posts have been made, but I have been unable to figure it out and am quite desperate! I can provide the stack trace if necessary, but it is quite long as there is a trace for each parser.
File URI need to be absolute for OWLAPI to parse them, but as you have a local file you can just create a File instance and pass that to IRI.create().
Alternatively pass the File instance to OWLOntologyManager::loadOntologyFromOntologyDocument()
There must be something wrong with the local, downloaded file. Loading the ontology directly from the ontology IRI worked.
I'm trying to read an N-Quads file with Jena, but all I get is an empty model. The file I'm trying to read is taken from the example in N-Quads documentation:
<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> <http://example.org/graphs/spiderman> .
(I saved it as a file named file.nq).
The way I'm loading the model is using the RDFDataMgr. But it didn't work with Model.read either.
RDFDataMgr.loadModel("file.nq", Lang.NQUADS)
yields an empty model.
What am I missing? Doesn't Jena support N-Quads out-of-the-box?
Yes, Jena supports N-Quads. Try loadDataset.
N-Quads is for multiple graphs and you have read it into one graph. What you get is just the default graph triples, in this case, none.
There is a warning emitted:
WARN riot :: Only triples or default graph data expected : named graph data ignored
If you didn't get that then (1) you are running an old copy (2) you have turned logging off (3) the file is empty.
I have a project where I need to parse an RDF file and record all the data on which I will have to search for specific data afterwards. I searched the web and all I could find was how to query the said RDF file but I want to parse it and save all the classes in objects.
This is how a class looks in my file:
<BFO rdf:about="BFO:0000007">
<rdfs:label>process</rdfs:label>
<Definition>
<rdf:Description>
<def>A process is an entity that exists in time by occurring or happening, has temporal parts and always involves and depends on some entity during the time it occurs.</def>
</rdf:Description>
</Definition>
<is_a rdf:resource="EFO:0000001"/>
</BFO>
Update:
yea all u said worked, thank you very much for that but one last question:) the namespaces i have are:
<?xml version='1.0' encoding='UTF-8'?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns="http://www.ebi.ac.uk/efo/">
</rdf>
My question is for the
<Definition>
<rdf:Description>
<def>smth here</def>
</rdf:Description>
</Definition>
i couldn't find a way to get the def tag, any idea how i can access it? sry to bother again:)
Jena uses the Model object to store RDF that has been parsed from an external source, such as a file or web URL. Depending on your project's needs, and the size of the data, you have a basic choice of whether to read the file into a memory Model, or a persistent Model. Memory is generally faster to access, but of course once your program exits the contents of the memory model are lost (well, unless you write them to a file again).
You should read the Jena tutorials to get a better understanding of the processes involved, but reading a file into a Jena memory model is very easy:
String source = ".. your file location ..";
Model m = FileManager.get().loadModel( source, "RDF/XML" );
If a persistent model would better suit your project, the best choice is Jena TDB. Again, it's very easy to get a model that you can begin querying.
You also asked:
and save all the classes in objects
I'm not quite sure what you mean here. Possibly you're thinking of some sort of ORM tool, similar to ActiveRecord? There's nothing built-in to Jena to do that, though there have been various other projects that have looked at doing something like an ORM layer. I'm not sure which of them is currently active though. But you don't need an ORM to access the properties of your resources, you can just use the Jena API:
String namespace = ".. your namespace here ..";
Resource bfo = m.getResource( namespace + "BFO:0000007" );
Property definition = m.getProperty( namespace + "Definition" );
RDFNode def = bfo.getProperty( definition ).getObject();
Updated
OK, in response to the comments: if you don't know which properties to expect on a resource, you can list them:
String namespace = ".. your namespace here ..";
Resource bfo = m.getResource( namespace + "BFO:0000007" );
for (StmtIterator i = bfo.listProperties(); i.hasNext(); ) {
Statement smt = i.next();
System.out.println( "Resource " + stmt.getSubject().getURI() +
" has property " + stmt.getPredicate().getURI() +
" with value " + stmt.getObject() );
}
This is just a very simple loop, you will want to do something much more useful, but hopefully that shows you that you can still process the resources in the model without knowing their properties in advance. Of course, at some point in your code you will have to connect a particular property to whatever your application wants to do with that particular value of the resource. So somewhere your code will have to have some knowledge of which properties to expect.
Re-reading your comment, I notice you refer to "concepts in an ontology" (even though there are no classes in the RDF fragment you quoted in the question). You might find the capabilities of the Jena ontology API useful, which can list the ontology classes in a model, the properties that have been defined, etc.