How to read an ontology (owl file) using jena and populate this ontology (ontModel) from a CSV file then write the populated OntModel into OWL file
相关问题
- jena.query.ResultSet and jena.query.QuerySolution:
- merge equivalent classes using owl API
- OWL RDF/TTL Make an instance member of class based
- Adding more individuals to existing RDF ontology
- Unable to resolve NoClassDefFoundError for Jena IR
相关文章
- How to turn a SPARQL/SPIN query/rule into an RDF s
- Meaning of owl:hasValue?
- Jena Fuseki assembler file + TDB + OWL reasoner
- Saving and reusing the result of a SPARQL query
- RDFS: same property for multiple domains
- OWL ObjectProperty loading as annotation in Protég
- owl - protege not inferring correctly? how to defi
- Jena TDB to store and query using API
There are three parts to your question:
Model
Model
out to a fileThe first and third of these are easy with Jena (see
Model.read()
andModel.write()
methods, and theFileManager
for some additional convenience support for reading from different locations).The second part is the tricky one. Typically, when converting a CSV file to RDF, we assume that each row represents one RDF resource and its properties. You have three tasks to achieve:
For example, consider the following CSV:
We can use the first row of the CSV to suggest RDF predicate names.
foaf:name
andfoaf:age
would be appropriate choices for the first two columns, but we may need a new predicate in our namespace for the third columnhttp://example.com/vocab#occupation
. The resource URI will be based on whatever the key is for the data, in this case theid
column, suggesting that the URI for the resource denoted by the first row will behttp://example.com/data/employee/2718
. Finally we have to map the data. The name is just a string, the age is an integer and the occupation is a resource. Given those choices, we may end up with output like:The W3C working draft R2RML defines a standardised mapping language for performing these kinds of translations. Various implementations of R2RML are available. Of course, if your mapping is fairly stable it would be perfectly straightforward just to write some code to perform the translation from CSV for your particular input data.