public static void main(String[] args) throws Exception{ // StringRenderer.setRenderer(Rendering.DL_SYNTAX); Logger.getRootLogger().setLevel(Level.INFO); Logger.getLogger(PCELOE.class).setLevel(Level.DEBUG); Logger.getLogger(PCELOE.class).addAppender(new FileAppender(new PatternLayout( "[%t] %c: %m%n" ), "log/parallel_run.txt", false)); AbstractKnowledgeSource ks = new OWLFile("../examples/family/father_oe.owl"); ks.init(); AbstractReasonerComponent rc = new ClosedWorldReasoner(ks); rc.init(); ClassLearningProblem lp = new ClassLearningProblem(rc); lp.setClassToDescribe(new OWLClassImpl(IRI.create("http://example.com/father#father"))); lp.setCheckConsistency(false); lp.init(); PCELOE alg = new PCELOE(lp, rc); alg.setMaxExecutionTimeInSeconds(10); alg.setNrOfThreads(4); // alg.setMaxClassDescriptionTests(200); alg.init(); alg.start(); }
/** * Removes a knowledge source with the given URL (independant of its type). * @param url URL of the OWL file or SPARQL Endpoint. * @return True if a knowledge source was deleted, false otherwise. */ public boolean removeKnowledgeSource(String url) { Iterator<AbstractKnowledgeSource> it = knowledgeSources.iterator(); while(it.hasNext()) { AbstractKnowledgeSource source = it.next(); if((source instanceof OWLFile && ((OWLFile)source).getURL().toString().equals(url)) || (source instanceof SparqlKnowledgeSource && ((SparqlKnowledgeSource)source).getURL().toString().equals(url)) ) { it.remove(); return true; } } return false; }
@Override public void init() throws ComponentInitException { setReasoning(getReasoningString()); if (sparql != null) { StringBuilder sb = new StringBuilder();
} else { OWLFile owl_file = (OWLFile) abstract_ks; Model model = RDFDataMgr.loadModel(owl_file.getURL().getFile()); logger.debug(sparql_debug, "file reasoning: " + ((owl_file.getReasoning() == null || owl_file.getReasoning().getReasonerFactory() == null) ? "(none)" : owl_file.getReasoning().getReasonerFactory().getURI())); ks = new LocalModelBasedSparqlEndpointKS(model, owl_file.getReasoning());
OWLFile ks = new OWLFile(); ks.setFileName(familyExamplesDir.getAbsolutePath() + "/father.owl"); ks.init();
@Test public void nlp2rdfTest() throws ComponentInitException { // read file into reasoner OWLFile file = new OWLFile("src/test/resources/nlp2rdf/positives.owl"); file.init(); ClosedWorldReasoner fic = new ClosedWorldReasoner(); fic.setSources(file); fic.init(); OWLDataFactory df = new OWLDataFactoryImpl(); OWLClass doc = df.getOWLClass(IRI.create("http://nlp2rdf.lod2.eu/schema/string/Document")); OWLObjectProperty op = df.getOWLObjectProperty(IRI.create("http://nlp2rdf.lod2.eu/schema/string/subStringTrans")); OWLObjectSomeValuesFrom osr = df.getOWLObjectSomeValuesFrom(op, df.getOWLThing()); OWLObjectIntersectionOf is = df.getOWLObjectIntersectionOf(doc,osr); OWLIndividual ind = df.getOWLNamedIndividual(IRI.create("http://nlp2rdf.org/POS/2/offset_0_763_COPPER+STUDY+GROUP+C")); // System.out.println(); // there should be several subStringTrans relations assertFalse(fic.getRelatedIndividuals(ind, op).isEmpty()); // individual should be member of this expression (required to learn the correct concept) assertTrue(fic.hasType(is, ind)); }
((OWLFile) ks).setUrl(new URL(url));
public static void main(String[] args) throws Exception { KnowledgeSource ks = new OWLFile("../examples/swore/swore.rdf"); AbstractReasonerComponent rc = new ClosedWorldReasoner(ks); rc.init(); ClassLearningProblem lp = new ClassLearningProblem(rc); lp.setClassToDescribe(new OWLClassImpl(IRI.create("http://ns.softwiki.de/req/CustomerRequirement"))); lp.init(); CELOE celoe = new CELOE(lp, rc); celoe.setNoisePercentage(1.0); celoe.setMaxExecutionTimeInSeconds(3); celoe.init(); celoe.start(); List<OWLClassExpression> descriptions = new ArrayList<>(); for (EvaluatedDescription<? extends Score> ed : celoe.getCurrentlyBestEvaluatedDescriptions(100)) { if(((EvaluatedDescriptionClass)ed).getAdditionalInstances().size() > 0){ System.out.println(ed); System.out.println(((EvaluatedDescriptionClass)ed).getAdditionalInstances()); descriptions.add(ed.getDescription()); } if(descriptions.size() == 3) break; } // descriptions.addAll(celoe.getCurrentlyBestDescriptions(2)); // descriptions.add(new NamedClass("http://ns.softwiki.de/req/Requirement")); // descriptions.add(new NamedClass("http://ns.softwiki.de/req/Customer")); DescriptionLinearClassifier dlc = new DescriptionLinearClassifier(lp, rc); dlc.getLinearCombination(descriptions); }
@Override public OWLOntology createOWLOntology(OWLOntologyManager manager) { try { return manager.loadOntologyFromOntologyDocument(IRI.create(getURL().toURI())); } catch (OWLOntologyCreationException | URISyntaxException e) { throw new RuntimeException(e); } }
@Test public void test4() throws ComponentInitException, ParseException, IOException { Logger logger = Logger.getRootLogger(); logger.setLevel(Level.TRACE); SimpleLayout layout = new SimpleLayout(); FileAppender app = new FileAppender(layout, "log/el/log.txt", false); logger.removeAllAppenders(); logger.addAppender(app); String ont = "../test/galen2.owl"; KnowledgeSource source = new OWLFile(ont); source.init(); AbstractReasonerComponent reasoner = new OWLAPIReasoner(Collections.singleton(source)); reasoner.init(); System.out.println("Galen loaded."); // Description input = KBParser.parseConcept("(\"http://www.co-ode.org/ontologies/galen#15.0\" AND (\"http://www.co-ode.org/ontologies/galen#30.0\" AND (EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#5.0\" AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#6.0\")))"); OWLClassExpression input = KBParser.parseConcept("(\"http://www.co-ode.org/ontologies/galen#1.0\" AND (\"http://www.co-ode.org/ontologies/galen#10.0\" AND (EXISTS \"http://www.co-ode.org/ontologies/galen#DomainAttribute\".(\"http://www.co-ode.org/ontologies/galen#1.0\" AND (\"http://www.co-ode.org/ontologies/galen#6.0\" AND \"http://www.co-ode.org/ontologies/galen#TopCategory\")) AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".(\"http://www.co-ode.org/ontologies/galen#1.0\" AND (\"http://www.co-ode.org/ontologies/galen#TopCategory\" AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".TOP)))))"); input = ConceptTransformation.cleanConcept(input); ELDown operator = new ELDown(reasoner); operator.init(); operator.refine(input); }
private void loadModel(){ model = ModelFactory.createDefaultModel(); for (KnowledgeSource ks : reasoner.getSources()) { if(ks instanceof OWLFile){ try { model.read(((OWLFile) ks).getURL().openStream(), null); } catch (IOException e) { e.printStackTrace(); } } else if(ks instanceof OWLAPIOntology){ ByteArrayInputStream bais = new ByteArrayInputStream(((OWLAPIOntology) ks).getConverter().convert(((OWLAPIOntology) ks).getOntology())); model.read(bais, null); try { bais.close(); } catch (IOException e) { e.printStackTrace(); } } } }
KnowledgeSource source = new OWLFile(example);
private void loadModel(){ model = ModelFactory.createDefaultModel(); for (KnowledgeSource ks : reasoner.getSources()) { if(ks instanceof OWLFile){ try { model.read(((OWLFile) ks).getURL().openStream(), null); } catch (IOException e) { e.printStackTrace(); } } else if(ks instanceof OWLAPIOntology){ ByteArrayInputStream bais = new ByteArrayInputStream(((OWLAPIOntology) ks).getConverter().convert(((OWLAPIOntology) ks).getOntology())); model.read(bais, null); try { bais.close(); } catch (IOException e) { e.printStackTrace(); } } } }
AbstractKnowledgeSource source = new OWLFile(example);
StringRenderer.setRenderer(Rendering.DL_SYNTAX); String file = "../examples/family/father_oe_inv.ttl"; KnowledgeSource ks = new OWLFile(file); AbstractReasonerComponent reasoner = new OWLAPIReasoner(Collections.singleton(ks)); reasoner.init();
StringRenderer.setRenderer(Rendering.DL_SYNTAX); String file = "../examples/carcinogenesis/carcinogenesis.owl"; KnowledgeSource ks = new OWLFile(file); AbstractReasonerComponent reasoner = new OWLAPIReasoner(Collections.singleton(ks)); reasoner.init();
try { String file = "../examples/carcinogenesis/carcinogenesis.owl"; KnowledgeSource ks = new OWLFile(file); AbstractReasonerComponent reasoner = new OWLAPIReasoner(Collections.singleton(ks)); reasoner.init();
@Test public void asTest() throws ComponentInitException, MalformedURLException { String ont = "../test/galen2.owl"; KnowledgeSource source = new OWLFile(ont); source.init(); AbstractReasonerComponent reasoner = new OWLAPIReasoner(Collections.singleton(source)); reasoner.init(); System.out.println("Galen loaded."); ELDescriptionTree tree = new ELDescriptionTree(reasoner); OWLClass a1 = new OWLClassImpl(IRI.create("http://www.co-ode.org/ontologies/galen#1.0")); OWLClass a2 = new OWLClassImpl(IRI.create("http://www.co-ode.org/ontologies/galen#10.0")); OWLClass a3 = new OWLClassImpl(IRI.create("http://www.co-ode.org/ontologies/galen#6.0")); OWLClass a4 = new OWLClassImpl(IRI.create("http://www.co-ode.org/ontologies/galen#TopCategory")); OWLObjectProperty r1 = new OWLObjectPropertyImpl(IRI.create("http://www.co-ode.org/ontologies/galen#Attribute")); OWLObjectProperty r2 = new OWLObjectPropertyImpl(IRI.create("http://www.co-ode.org/ontologies/galen#DomainAttribute")); ELDescriptionNode v1 = new ELDescriptionNode(tree, a1, a2); ELDescriptionNode v2 = new ELDescriptionNode(v1, r2, a1, a3, a4); ELDescriptionNode v3 = new ELDescriptionNode(v1, r1, a1, a4); new ELDescriptionNode(v3, r1); ELDescriptionNode w = new ELDescriptionNode(v2, r1); ELDown operator = new ELDown(reasoner); operator.init(); System.out.println(operator.asCheck(w)); }
source = new OWLFile(owlFile);