Coder Social home page Coder Social logo

ont-converter's Introduction

Ontology Converter v2.0

A simple command-line utility to convert any RDF graph to OWL2-DL ontology.

This is a kind of ONT-API extension. Can work both with single ontology file source and with directory containing dependent or independent ontology document sources. The utility automatically transforms the source RDF Graph to the OWL2 DL syntax according to the internal rules and command-line options. For example, if there is no owl:Ontology section inside rdf-graph (which is required by OWL), an anonymous ontology header will be generated. The tool is available in the form of code and prebuilt jar (see /releases), and as a library at jitpack.io.

Usage: java -jar ont-converter.jar [-f] [-h] -i <path> [-if <format>] -o <path> -of <format> [-p <0|1|2>] [-r] [-v] [-w]

Options:

  • -f,--force Ignore any exceptions while loading/saving and processing imports.
  • -i,--input The file path or not-empty directory to load ontology/ontologies. (always required) { String }
  • -if,--input-format The input format. If not specified the program will choose the most suitable one to load ontology from a file. { Value should be one of [{0, ttl, TURTLE}, {1, rdf, RDF_XML, RDF/XML}, {2, rj, RDF_JSON, RDF/JSON}, {3, jsonld, JSON_LD, JSON-LD}, {4, nt, NTRIPLES, N-Triples}, {5, nq, NQUADS, N-Quads}, {6, trig}, {7, trix}, {8, trdf, RDF_THRIFT, RDF-THRIFT}, {11, owl, OWL_XML, OWL/XML}, {12, omn, MANCHESTER_SYNTAX, ManchesterSyntax}, {13, fss, FUNCTIONAL_SYNTAX, FunctionalSyntax}, {18, krss2}, {19, dl}] }
  • -o,--output The file or directory path to store result ontology/ontologies.If the --input is a file then this parameter must also be a file. (always required) { String }
  • -of,--output-format The format of output ontology/ontologies. (always required) { Value should be one of [{0, ttl, TURTLE}, {1, rdf, RDF_XML, RDF/XML}, {2, rj, RDF_JSON, RDF/JSON}, {3, jsonld, JSON_LD, JSON-LD}, {4, nt, NTRIPLES, N-Triples}, {5, nq, NQUADS, N-Quads}, {6, trig}, {7, trix}, {8, trdf, RDF_THRIFT, RDF-THRIFT}, {11, owl, OWL_XML, OWL/XML}, {12, omn, MANCHESTER_SYNTAX, ManchesterSyntax}, {13, fss, FUNCTIONAL_SYNTAX, FunctionalSyntax}, {18, krss2}, {19, dl}, {20, html, DL_HTML, DL/HTML}, {21, tex, LATEX}] }
  • -p,--punnings The punning mode. Could be used in conjunction with --refine option. Must be one of the following:Lax mode: allows any punnings, i.e. ontology is allowed to contain multiple entity declarationsMiddle mode: two forbidden intersections: Datatype <-> Class & NamedObjectProperty <-> DatatypePropertyStrict mode: all punnings are forbidden, i.e. Datatype <-> Class and rdf:Property intersections(any pairs of NamedObjectProperty, DatatypeProperty, AnnotationProperty). { Value should be one of [{0, STRICT}, {1, MEDIUM}, {2, LAX}] }
  • -r,--refine Refine output: if specified the resulting ontologies will consist only of the OWL2-DL components (annotations and axioms), otherwise there could be some rdf-stuff (in case the output format is provided by jena)
  • -v,--verbose To print progress messages to console.
  • -w,--web Allow web/ftp diving to retrieve dependent ontologies from imports (owl:imports),otherwise the specified directory (see --input) will be used as the only source.

Example (RDF/XML -> Manchester Syntax):

$ java -jar ont-converter.jar -i /tmp/pizza.owl.xml -if 1 -o /tmp/pizza.omn -of 12 -v

where

  • -i /tmp/pizza.owl.xml - the path to existing source file, required. In the example above it is pizza.owl.
  • -if 1 - the explicit input format (could be also -if rdf, -if rdf/xml or -if rdf_xml), optional.
  • -o /tmp/pizza.omn - the path to target file, required.
  • -of 12 - the output format (could be also -of omn, -of manchestersyntax, -of manchester_syntax), required.
  • -v - to print progress info to console, optional.

Load API

Some facilities from the tool internals can be used as a library to simplify bulk loading. This can be helpful to properly handle all owl:imports dependencies. See examples:

import com.github.owlcs.ontapi.OntFormat;
import com.github.sszuev.ontconverter.api.LoadersKt;
import com.github.sszuev.ontconverter.api.ManagersKt;
import com.github.sszuev.ontconverter.api.OntologyMap;

List<OntologyMap> maps = LoadersKt.loadDirectory(Path.of("/path-to-dir-with-ontologies"), null, false, ManagersKt::createSoftManager);
maps.forEach(map -> map.getIds().forEach((iri, id) -> System.out.println("document-iri = " + iri + " => id=" + id)));
maps.forEach(map -> map.getGraphs().forEach((iri, g) -> System.out.println("document-iri = " + iri + " => triples=" + g.size())));
maps.forEach(map -> map.sources().iterator().forEachRemaining(s -> System.out.println("document-source = " + s)));

OntologyMap map = LoadersKt.loadFile(Path.of("/path-to-file-ttl"), OntFormat.TURTLE, false, ManagersKt.createSoftManager());
System.out.println(map);

Requirements:

Build:

  • To build use gradle clean build running in the project root.
  • To install into local maven repository (.m2) use gradle publishToMavenLocal
  • To run from the project root use command java -jar build/libs/ont-converter.jar

Issues:

Please use /ont-converter/issues page

Dependencies:

ONT-API (version 3.0.0)

Full list of supported formats:

Name Provider Read / Write Aliases (case insensitive)
TURTLE Apache Jena yes / yes 0, turtle, ttl
RDF_XML Apache Jena yes / yes 1, rdf_xml, rdf/xml, rdf
RDF_JSON Apache Jena yes / yes 2, rdf_json, rdf/json, rj
JSON_LD Apache Jena yes / yes 3, json_ld, json-ld, jsonld
NTRIPLES Apache Jena yes / yes 4, ntriples, n-triples, nt
NQUADS Apache Jena yes / yes 5, nquads, n-quads, nq
TRIG Apache Jena yes / yes 6, trig
TRIX Apache Jena yes / yes 7, trix
RDF_THRIFT Apache Jena yes / yes 8, rdf_thrift, rdf-thrift, trdf
OWL_XML OWL-API yes / yes 11, owl_xml, owl/xml, owl
MANCHESTER_SYNTAX OWL-API yes / yes 12, manchester_syntax, manchestersyntax, omn
FUNCTIONAL_SYNTAX OWL-API yes / yes 13, functional_syntax, functionalsyntax, fss
BINARY_RDF OWL-API yes / yes 14, binary_rdf, binaryrdf, brf
RDFA OWL-API yes / no 15, rdfa, xhtml
OBO OWL-API yes / yes 16, obo
KRSS2 OWL-API yes / yes 18, krss2
DL OWL-API yes / yes 19, dl
DL_HTML OWL-API no / yes 20, dl_html, dl/html, html
LATEX OWL-API no / yes 21, latex, tex

ont-converter's People

Contributors

sszuev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ont-converter's Issues

Failed for custom datatype

Tried the 1.0 release on some small DBpedia ABox dataset and got an exception due to a custom datatype (I guess):

Data (dummy.nt):

<http://dbpedia.org/resource/Belgium>	<http://dbpedia.org/ontology/PopulatedPlace/populationDensity>	"363.6"^^<http://dbpedia.org/datatype/inhabitantsPerSquareKilometre> .
<http://dbpedia.org/resource/Belgium>	<http://dbpedia.org/ontology/PopulatedPlace/populationDensity>	"363.58468065625044"^^<http://dbpedia.org/datatype/inhabitantsPerSquareKilometre> .
<http://dbpedia.org/resource/London>	<http://dbpedia.org/ontology/PopulatedPlace/populationDensity>	"5518.0"^^<http://dbpedia.org/datatype/inhabitantsPerSquareKilometre> .

Usage:

java -jar ont-converter.jar -i dummy.nt -o dummy.owl -of MANCHESTER_SYNTAX

Stacktrace:

Exception in thread "main" org.apache.jena.ontology.ConversionException: Can't wrap node http://dbpedia.org/datatype/inhabitantsPerSquareKilometre to class ru.avicomp.ontapi.jena.impl.OntDatatypeImpl
	at ru.avicomp.ontapi.jena.impl.conf.CommonOntObjectFactory.wrap(CommonOntObjectFactory.java:61)
	at org.apache.jena.enhanced.EnhNode.convertTo(EnhNode.java:152)
	at org.apache.jena.enhanced.EnhNode.convertTo(EnhNode.java:31)
	at org.apache.jena.enhanced.Polymorphic.asInternal(Polymorphic.java:62)
	at org.apache.jena.enhanced.EnhNode.as(EnhNode.java:107)
	at ru.avicomp.ontapi.internal.NoCacheDataFactory.get(NoCacheDataFactory.java:135)
	at ru.avicomp.ontapi.internal.DataPropertyAssertionTranslator.toAxiom(DataPropertyAssertionTranslator.java:63)
	at ru.avicomp.ontapi.internal.AxiomTranslator.lambda$translate$0(AxiomTranslator.java:93)
	at org.apache.jena.util.iterator.Map1Iterator.next(Map1Iterator.java:46)
	at java.util.Iterator.forEachRemaining(Iterator.java:116)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
	at ru.avicomp.ontapi.internal.InternalModel$ObjectTriplesMap.create(InternalModel.java:809)
	at ru.avicomp.ontapi.internal.InternalModel.readAxiomTriples(InternalModel.java:595)
	at ru.avicomp.ontapi.internal.InternalModel.readObjectTriples(InternalModel.java:559)
	at com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalLoadingCache.lambda$new$0(BoundedLocalCache.java:3366)
	at com.github.benmanes.caffeine.cache.BoundedLocalCache.lambda$doComputeIfAbsent$14(BoundedLocalCache.java:2039)
	at java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1853)
	at com.github.benmanes.caffeine.cache.BoundedLocalCache.doComputeIfAbsent(BoundedLocalCache.java:2037)
	at com.github.benmanes.caffeine.cache.BoundedLocalCache.computeIfAbsent(BoundedLocalCache.java:2020)
	at com.github.benmanes.caffeine.cache.LocalCache.computeIfAbsent(LocalCache.java:112)
	at com.github.benmanes.caffeine.cache.LocalLoadingCache.get(LocalLoadingCache.java:67)
	at ru.avicomp.ontapi.internal.InternalModel.getAxiomTripleStore(InternalModel.java:539)
	at ru.avicomp.ontapi.internal.InternalModel.lambda$listOWLAxioms$10(InternalModel.java:443)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
	at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:313)
	at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:743)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
	at ru.avicomp.ontapi.internal.InternalModel.readOWLObjects(InternalModel.java:307)
	at com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalLoadingCache.lambda$new$0(BoundedLocalCache.java:3366)
	at com.github.benmanes.caffeine.cache.BoundedLocalCache.lambda$doComputeIfAbsent$14(BoundedLocalCache.java:2039)
	at java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1853)
	at com.github.benmanes.caffeine.cache.BoundedLocalCache.doComputeIfAbsent(BoundedLocalCache.java:2037)
	at com.github.benmanes.caffeine.cache.BoundedLocalCache.computeIfAbsent(BoundedLocalCache.java:2020)
	at com.github.benmanes.caffeine.cache.LocalCache.computeIfAbsent(LocalCache.java:112)
	at com.github.benmanes.caffeine.cache.LocalLoadingCache.get(LocalLoadingCache.java:67)
	at ru.avicomp.ontapi.internal.InternalModel.listOWLObjects(InternalModel.java:293)
	at ru.avicomp.ontapi.internal.InternalModel.listOWLAnnotationProperties(InternalModel.java:272)
	at ru.avicomp.ontapi.OntBaseModelImpl.annotationPropertiesInSignature(OntBaseModelImpl.java:258)
	at org.semanticweb.owlapi.manchestersyntax.renderer.ManchesterOWLSyntaxFrameRenderer.writeOntology(ManchesterOWLSyntaxFrameRenderer.java:252)
	at org.semanticweb.owlapi.manchestersyntax.renderer.ManchesterSyntaxStorer.storeOntology(ManchesterSyntaxStorer.java:39)
	at org.semanticweb.owlapi.util.AbstractOWLStorer.store(AbstractOWLStorer.java:85)
	at org.semanticweb.owlapi.util.AbstractOWLStorer.storeOntology(AbstractOWLStorer.java:72)
	at org.semanticweb.owlapi.util.AbstractOWLStorer.storeOntology(AbstractOWLStorer.java:111)
	at ru.avicomp.ontapi.OntologyManagerImpl.write(OntologyManagerImpl.java:1654)
	at ru.avicomp.ontapi.OntologyManagerImpl.saveOntology(OntologyManagerImpl.java:1605)
	at ru.avicomp.ontapi.OntologyManagerImpl.saveOntology(OntologyManagerImpl.java:1585)
	at com.github.sszuev.Main.save(Main.java:148)
	at com.github.sszuev.Main.processFile(Main.java:68)
	at com.github.sszuev.Main.process(Main.java:55)
	at com.github.sszuev.Main.main(Main.java:47)

Is this not supported yet or already solved in a the newer version of Ont-API? I can see that Ont-Converter still depends on the version 1.4.0-SNAPSHOT

Build fails with message "The POM for ru.avicomp:ontapi:jar:1.4.0-SNAPSHOT is missing"

full error message:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.github.sszuev:ont-converter >-------------------
[INFO] Building ont-converter 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for ru.avicomp:ontapi:jar:1.4.0-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.836 s
[INFO] Finished at: 2022-03-24T16:45:38Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project ont-converter: Could not resolve dependencies for project com.github.sszuev:ont-converter:jar:1.0-SNAPSHOT: Failure to find ru.avicomp:ontapi:jar:1.4.0-SNAPSHOT in https://oss.sonatype.org/content/repositories/snapshots was cached in the local repository, resolution will not be reattempted until the update interval of snapshots-repo has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

Is this a problem at my end or is there an issue with this dependency?

Build infos missing

It would be nice, if there was some hint in the README on how to locally built the .jar file.

return support for jena-csv and topbraid-spin in v2

support for jena-csv and topbraid-spin is present in v1.
but both libraries are now deprecated, so I don't like much the idea of reanimating that code in v2,
on the other hand if these functionalities (or any of them) are really in use, the support should be returned back.

Can anyone who uses this tool clarify the issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.