org.semanticweb.owlapi.util.SimpleShortFormProvider Java Examples
The following examples show how to use
org.semanticweb.owlapi.util.SimpleShortFormProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryingWithNamedClasses.java From elk-reasoner with Apache License 2.0 | 6 votes |
public QueryingWithNamedClasses() throws OWLOntologyCreationException { // Traditional setup with the OWL-API manager = OWLManager.createOWLOntologyManager(); IRI ontologyIri = IRI.create(EL_ONTOLOGY); ontology = manager.loadOntologyFromOntologyDocument(ontologyIri); System.out.println("Loaded ontology: " + ontology.getOntologyID()); // But we use the Elk reasoner (add it to the classpath) reasonerFactory = new ElkReasonerFactory(); reasoner = reasonerFactory.createReasoner(ontology); // IMPORTANT: Precompute the inferences beforehand, otherwise no results // will be returned reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); // Ontologies are not easy to query with the full name of concept, so we // keep only the interesting bit ( = shortform) shortFormProvider = new SimpleShortFormProvider(); Set<OWLOntology> importsClosure = ontology.getImportsClosure(); mapper = new BidirectionalShortFormProviderAdapter(manager, importsClosure, shortFormProvider); }
Example #2
Source File: Report.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Create a new report object with a QuotedEntityChecker loaded with entries from the label map. * Use labels for report output. * * @param labelMap Map of IRI to label for all entities in the ontology * @throws IOException on problem creating IOHelper */ public Report(Map<IRI, String> labelMap) throws IOException { this.ioHelper = new IOHelper(); checker = new QuotedEntityChecker(); checker.setIOHelper(ioHelper); checker.addProvider(new SimpleShortFormProvider()); checker.addProperty(OWLManager.getOWLDataFactory().getRDFSLabel()); if (labelMap != null) { useLabels = true; OWLDataFactory df = OWLManager.getOWLDataFactory(); for (Entry<IRI, String> entry : labelMap.entrySet()) { // Set all the entities as class - will not matter for retrieving label OWLEntity e = df.getOWLEntity(EntityType.CLASS, entry.getKey()); checker.add(e, entry.getValue()); } } }
Example #3
Source File: Template.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Given a template name and a list of rows, create a template object with a new IOHelper and * QuotedEntityChecker. The rows are added to the object, new labels from the rows are added to * the checker, and a Manchester Syntax parser is created. * * @param name template name * @param rows list of rows (lists) * @throws Exception on issue creating IOHelper or adding table to template object */ public Template(@Nonnull String name, @Nonnull List<List<String>> rows) throws Exception { this.name = name; this.ioHelper = new IOHelper(); tableRows = new ArrayList<>(); templates = new ArrayList<>(); headers = new ArrayList<>(); axioms = new HashSet<>(); checker = new QuotedEntityChecker(); checker.setIOHelper(this.ioHelper); checker.addProvider(new SimpleShortFormProvider()); // Add the contents of the tableRows addTable(rows); addLabels(); createParser(); }
Example #4
Source File: Template.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Given a template name, a list of rows, and an IOHelper, create a template object with a new * QuotedEntityChecker. The rows are added to the object, new labels from the rows are added to * the checker, and a Manchester Syntax parser is created. * * @param name template name * @param rows list of rows (lists) * @param ioHelper IOHelper to resolve prefixes * @throws Exception on issue adding table to template object */ public Template(@Nonnull String name, @Nonnull List<List<String>> rows, IOHelper ioHelper) throws Exception { this.name = name; this.ioHelper = ioHelper; tableRows = new ArrayList<>(); templates = new ArrayList<>(); headers = new ArrayList<>(); axioms = new HashSet<>(); checker = new QuotedEntityChecker(); checker.setIOHelper(this.ioHelper); checker.addProvider(new SimpleShortFormProvider()); checker.addProperty(dataFactory.getRDFSLabel()); // Add the contents of the tableRows addTable(rows); addLabels(); createParser(); }
Example #5
Source File: Template.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Given a template name, a list of rows, and an input ontology, create a template object with a * new IOHelper and QuotedEntityChecker populated by the input ontology. The rows are added to the * object, new labels from the rows are added to the checker, and a Manchester Syntax parser is * created. * * @param name template name * @param rows list of rows (lists) * @param inputOntology OWLOntology to get labels of entities for QuotedEntityChecker * @throws Exception on issue creating IOHelper or adding table to template object */ public Template(@Nonnull String name, @Nonnull List<List<String>> rows, OWLOntology inputOntology) throws Exception { this.name = name; ioHelper = new IOHelper(); tableRows = new ArrayList<>(); templates = new ArrayList<>(); headers = new ArrayList<>(); axioms = new HashSet<>(); checker = new QuotedEntityChecker(); checker.setIOHelper(this.ioHelper); checker.addProvider(new SimpleShortFormProvider()); checker.addProperty(dataFactory.getRDFSLabel()); if (inputOntology != null) { checker.addAll(inputOntology); } // Add the contents of the tableRows addTable(rows); addLabels(); createParser(); }
Example #6
Source File: QuotedEntityCheckerTest.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Test resolving a label from an import. * * @throws Exception on any issue. */ @Test public void testImportLabel() throws Exception { OWLOntology ontology = loadOntologyWithCatalog("/import_test.owl"); QuotedEntityChecker checker = new QuotedEntityChecker(); checker.setIOHelper(new IOHelper()); checker.addProvider(new SimpleShortFormProvider()); checker.addProperty(dataFactory.getRDFSLabel()); checker.addAll(ontology); OWLEntity cls = checker.getOWLClass("test one"); if (cls != null) { assertEquals( "https://github.com/ontodev/robot/robot-core/src/test/resources/simple.owl#test1", cls.getIRI().toString()); } else { throw new Exception("Class 'test one' does not exist."); } }
Example #7
Source File: Report.java From robot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a new report object with an ontology (maybe) using labels for output. * * @param ontology OWLOntology to get labels from * @param useLabels if true, use labels for output * @throws IOException on problem creating IOHelper */ public Report(OWLOntology ontology, boolean useLabels) throws IOException { ioHelper = new IOHelper(); if (useLabels) { checker = new QuotedEntityChecker(); checker.setIOHelper(this.ioHelper); checker.addProvider(new SimpleShortFormProvider()); checker.addProperty(OWLManager.getOWLDataFactory().getRDFSLabel()); if (ontology != null) { checker.addAll(ontology); } } }
Example #8
Source File: Report.java From robot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a new report object with an ontology to (maybe) get labels from and a defined IOHelper. * * @param ontology OWLOntology to get labels from * @param ioHelper IOHelper to use * @param useLabels if true, use labels for output */ public Report(OWLOntology ontology, IOHelper ioHelper, boolean useLabels) { this.ioHelper = ioHelper; if (useLabels) { checker = new QuotedEntityChecker(); checker.setIOHelper(this.ioHelper); checker.addProvider(new SimpleShortFormProvider()); checker.addProperty(OWLManager.getOWLDataFactory().getRDFSLabel()); if (ontology != null) { checker.addAll(ontology); } } this.useLabels = useLabels; }
Example #9
Source File: Template.java From robot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Given a template name, a list of rows, an input ontology, and an IOHelper, create a template * object with a new QuotedEntityChecker with the IOHelper populated by the input ontology. The * rows are added to the object, new labels from the rows are added to the checker, and a * Manchester Syntax parser is created. * * @param name template name * @param rows list of rows (lists) * @param inputOntology OWLOntology to get labels of entities for QuotedEntityChecker * @param ioHelper IOHelper to resolve prefixes * @throws Exception on issue adding table to template object */ public Template( @Nonnull String name, @Nonnull List<List<String>> rows, OWLOntology inputOntology, IOHelper ioHelper) throws Exception { this.name = name; this.ioHelper = ioHelper; tableRows = new ArrayList<>(); templates = new ArrayList<>(); headers = new ArrayList<>(); axioms = new HashSet<>(); checker = new QuotedEntityChecker(); checker.setIOHelper(this.ioHelper); checker.addProvider(new SimpleShortFormProvider()); checker.addProperty(dataFactory.getRDFSLabel()); if (inputOntology != null) { checker.addAll(inputOntology); } // Add the contents of the tableRows addTable(rows); addLabels(); createParser(); }
Example #10
Source File: Template.java From robot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Given a template name, a list of rows, an IOHelper, and a QuotedEntityChecker, create a * template object. The rows are added to the object, new labels from the rows are added to the * checker, and a Manchester Syntax parser is created. * * @param name template name * @param rows list of rows (lists) * @param inputOntology OWLOntology to get labels of entities for QuotedEntityChecker * @param ioHelper IOHelper to resolve prefixes * @param checker QuotedEntityChecker to get entities by label * @throws Exception on issue adding table to template object */ public Template( @Nonnull String name, @Nonnull List<List<String>> rows, OWLOntology inputOntology, IOHelper ioHelper, QuotedEntityChecker checker) throws Exception { this.name = name; this.ioHelper = ioHelper; if (checker == null) { this.checker = new QuotedEntityChecker(); this.checker.setIOHelper(this.ioHelper); this.checker.addProvider(new SimpleShortFormProvider()); this.checker.addProperty(dataFactory.getRDFSLabel()); } else { this.checker = checker; } tableRows = new ArrayList<>(); templates = new ArrayList<>(); headers = new ArrayList<>(); axioms = new HashSet<>(); if (inputOntology != null) { this.checker.addAll(inputOntology); } // Add the contents of the tableRows addTable(rows); addLabels(); createParser(); parser.setOWLEntityChecker(this.checker); }
Example #11
Source File: TemplateHelperTest.java From robot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Set up the checker loaded with the input ontology * * @throws IOException on issue loading ontology */ @Before public void setUp() throws IOException { OWLOntology inputOntology = loadOntology("/uberon.owl"); checker = new QuotedEntityChecker(); checker.setIOHelper(new IOHelper()); checker.addProvider(new SimpleShortFormProvider()); checker.addProperty(dataFactory.getRDFSLabel()); if (inputOntology != null) { checker.addAll(inputOntology); } }
Example #12
Source File: ExplainCommand.java From robot with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public CommandState execute(CommandState state, String[] args) throws Exception { CommandLine line = CommandLineHelper.getCommandLine(getUsage(), getOptions(), args); if (line == null) { return null; } if (state == null) { state = new CommandState(); } IOHelper ioHelper = CommandLineHelper.getIOHelper(line); state = CommandLineHelper.updateInputOntology(ioHelper, state, line); OWLOntology ontology = state.getOntology(); QuotedEntityChecker checker = new QuotedEntityChecker(); checker.setIOHelper(ioHelper); checker.addProvider(new SimpleShortFormProvider()); checker.addProperty(OWLManager.getOWLDataFactory().getRDFSLabel()); checker.addAll(ontology); String maxString = CommandLineHelper.getDefaultValue(line, "max", "1"); final int max; try { max = Integer.parseInt(maxString); } catch (NumberFormatException e) { throw new Exception(String.format(maxTypeError, maxString)); } OWLReasonerFactory reasonerFactory = CommandLineHelper.getReasonerFactory(line, true); ManchesterOWLSyntaxInlineAxiomParser parser = new ManchesterOWLSyntaxInlineAxiomParser(OWLManager.getOWLDataFactory(), checker); String expression = CommandLineHelper.getRequiredValue(line, "axiom", "an --axiom is required"); OWLAxiom axiom = parser.parse(expression); Set<Explanation<OWLAxiom>> explanations = ExplainOperation.explain(axiom, ontology, reasonerFactory, max); if (line.hasOption("explanation")) { File output = new File(line.getOptionValue("explanation")); String result = explanations .stream() .map( e -> ExplainOperation.renderExplanationAsMarkdown( e, ontology.getOWLOntologyManager())) .collect(Collectors.joining("\n\n\n")); Writer writer = Files.newBufferedWriter(output.toPath(), StandardCharsets.UTF_8); writer.write(result); writer.close(); } Set<OWLAxiom> explanationsAxioms = explanations.stream().flatMap(e -> e.getAxioms().stream()).collect(Collectors.toSet()); Set<IRI> explanationTerms = explanationsAxioms .stream() .flatMap(ax -> ax.getSignature().stream().map(e -> e.getIRI())) .collect(Collectors.toSet()); Set<OWLAnnotationAssertionAxiom> annotations = OntologyHelper.getAnnotationAxioms( ontology, Collections.singleton(OWLManager.getOWLDataFactory().getRDFSLabel()), explanationTerms); explanationsAxioms.addAll(annotations); state.setOntology(ontology.getOWLOntologyManager().createOntology(explanationsAxioms)); CommandLineHelper.maybeSaveOutput(line, ontology); return state; }