constructs a TBox reasoner from an ontology
@param onto: ontology
16513
static ClassifiedTBox classify(OntologyImpl.UnclassifiedOntologyTBox onto) {

		DefaultDirectedGraph<ObjectPropertyExpression, DefaultEdge> objectPropertyGraph =
				getObjectPropertyGraph(onto);
		EquivalencesDAGImpl<ObjectPropertyExpression> objectPropertyDAG =
				EquivalencesDAGImpl.getEquivalencesDAG(objectPropertyGraph);

		DefaultDirectedGraph<DataPropertyExpression, DefaultEdge> dataPropertyGraph =
				getDataPropertyGraph(onto);
		EquivalencesDAGImpl<DataPropertyExpression> dataPropertyDAG =
				EquivalencesDAGImpl.getEquivalencesDAG(dataPropertyGraph);

		EquivalencesDAGImpl<ClassExpression> classDAG =
				EquivalencesDAGImpl.getEquivalencesDAG(getClassGraph(onto, objectPropertyGraph, dataPropertyGraph));

		EquivalencesDAGImpl<DataRangeExpression> dataRangeDAG =
				EquivalencesDAGImpl.getEquivalencesDAG(getDataRangeGraph(onto, dataPropertyGraph));

		chooseObjectPropertyRepresentatives(objectPropertyDAG);
		chooseDataPropertyRepresentatives(dataPropertyDAG);
		chooseClassRepresentatives(classDAG, objectPropertyDAG, dataPropertyDAG);
		chooseDataRangeRepresentatives(dataRangeDAG, dataPropertyDAG);

		ClassifiedTBoxImpl r = new ClassifiedTBoxImpl(
                onto.classes(),
                onto.objectProperties(),
                onto.dataProperties(),
                onto.annotationProperties(),
                classDAG,
                objectPropertyDAG,
                dataPropertyDAG,
                dataRangeDAG,
                onto.getDisjointClassesAxioms(),
                onto.getDisjointObjectPropertiesAxioms(),
                onto.getDisjointDataPropertiesAxioms(),
                onto.getReflexiveObjectPropertyAxioms(),
                onto.getIrreflexiveObjectPropertyAxioms(),
                onto.getFunctionalObjectProperties(),
                onto.getFunctionalDataProperties());
//		if (equivalenceReduced) {
//			r = getEquivalenceSimplifiedReasoner(r);
//		}
		return r;
	}
943672
private void init(NormalisedOntology ont) {
        parentTodo = ont.getTodo();
        contextIndex = ont.getContextIndex();
        ontologyNF1 = ont.getOntologyNF1();
        ontologyNF2 = ont.getOntologyNF2();
        ontologyNF3 = ont.getOntologyNF3();
        ontologyNF4 = ont.getOntologyNF4();
        ontologyNF5 = ont.getOntologyNF5();
        reflexiveRoles = ont.getReflexiveRoles();
        ontologyNF7 = ont.getOntologyNF7();
        ontologyNF8 = ont.getOntologyNF8();
        functionalFeatures = ont.getFunctionalFeatures();
        roleClosureCache = ont.getRoleClosureCache();
        factory = ont.getFactory();
        affectedContexts = ont.getAffectedContexts();
    }
875176
def render_subgraph(self, ontol, nodes, **args):
        
        subont = ontol.subontology(nodes, **args)
        return self.render(subont, **args)
910062
@Override
	public void actionPerformed(ActionEvent arg0) {

        try {
		final OWLWorkspace workspace = editorKit.getWorkspace();
            if (obdaModel.getSources().isEmpty())
            {
                JOptionPane.showMessageDialog(workspace, "The data source is missing. Create one in ontop Mappings. ");
            }
            else {
                // Get the path of the file of the active OWL model
                OWLOntology activeOntology = modelManager.getActiveOntology();
                IRI documentIRI = modelManager.getOWLOntologyManager().getOntologyDocumentIRI(activeOntology);

                File ontologyDir = new File(documentIRI.toURI().getPath());

                final JFileChooser fc = new JFileChooser(ontologyDir);
                final String shortForm = documentIRI.getShortForm();
                int i = shortForm.lastIndexOf(".");
                String ontologyName = (i < 1)?
                        shortForm:
                        shortForm.substring(0, i);
                fc.setSelectedFile(new File(ontologyName + "-mapping.ttl"));
                //fc.setSelectedFile(new File(sourceID + "-mapping.ttl"));

                int approve = fc.showSaveDialog(workspace);

                if(approve == JFileChooser.APPROVE_OPTION) {


                    final File file = fc.getSelectedFile();

                    Thread th = new Thread("R2RML Export Action Thread"){
                        @Override
                        public void run() {
                            try {
                                OBDAProgressMonitor monitor = new OBDAProgressMonitor(
                                        "Exporting the mapping to R2RML...", workspace);
                                R2RMLExportThread t = new R2RMLExportThread();
                                monitor.addProgressListener(t);
                                monitor.start();
                                t.run(file);
                                monitor.stop();
                                JOptionPane.showMessageDialog(workspace,
                                        "R2RML Export completed.", "Done",
                                        JOptionPane.INFORMATION_MESSAGE);
                            } catch (Exception e) {
                                JOptionPane.showMessageDialog(workspace, "An error occurred. For more info, see the logs.");
                                log.error("Error during R2RML export. \n", e.getMessage());
                                e.printStackTrace();
                            }
                        }
                    };
                    th.start();


                }
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(getWorkspace(), "An error occurred. For more info, see the logs.");
            log.error("Error during R2RML export. \n");
            ex.printStackTrace();
        }

	}
352636
def add_triples(self, ontol):
        
        rg = self.rdfgraph
        g = ontol.get_graph()
        typemap = {}
        inds = rg.subjects(RDF.type, OWL.NamedIndividual)
        for s in inds:
            for (s,p,o) in rg.triples((s,None,None)):
                s_id = id(s)
                p_id = id(p)
                g.add_node(s_id)
                if isinstance(o,URIRef):
                    o_id = id(o)
                    if p == RDF.type:
                        if o != OWL.NamedIndividual:
                            if s_id not in typemap:
                                typemap[s_id] = []
                            typemap[s_id].append(o_id)
                    else:
                        g.add_edge(o_id,s_id,pred=p_id)

        # propagate label from type
        for s in typemap.keys():
            g.nodes[s]['types'] = typemap[s]
            if self.tbox_ontology is not None:
                if 'label' not in g.nodes[s]:
                    g.nodes[s]['label'] = ";".join([self.tbox_ontology.label(x) for x in typemap[s] if self.tbox_ontology.label(x) is not None])
1128978
public Ontology parseOBO(
			BufferedReader oboFile,
			String ontoName,
			String ontoDescription
			)
					throws ParseException, IOException {

		try {
			OntologyFactory factory = OntoTools.getDefaultFactory();
			Ontology ontology = factory.createOntology(ontoName, ontoDescription);

			OboFileParser parser = new OboFileParser();

			OboFileEventListener handler = new OboFileHandler(ontology);

			parser.addOboFileEventListener(handler);
			parser.parseOBO(oboFile);

			return ontology;


		} catch (AlreadyExistsException ex) {
			throw new RuntimeException( "Duplication in ontology");
		} catch (OntologyException ex) {
			throw new RuntimeException(ex);
		}

	}
44649
def build(self, builder):
        
        builder.start("ReasonForChange", {})
        builder.data(self.reason)
        builder.end("ReasonForChange")
1171956
@Override
    public OWLAxiom visit(OWLSubClassOfAxiom axiom) {
        return dataFactory.getOWLSubClassOfAxiom(
                axiom.getSubClass().accept(this),
                axiom.getSuperClass().accept(this));
    }
1163961
def _build_basic_context(self):
        
        # printDebug(str(self.ontospy_graph.toplayer_classes))
        topclasses = self.ontospy_graph.toplayer_classes[:]
        if len(topclasses) < 3:  # massage the toplayer!
            for topclass in self.ontospy_graph.toplayer_classes:
                for child in topclass.children():
                    if child not in topclasses: topclasses.append(child)

        if not self.static_url:
            self.static_url = "static/"  # default

        context_data = {
            "STATIC_URL": self.static_url,
            "ontodocs_version": VERSION,
            "ontospy_graph": self.ontospy_graph,
            "topclasses": topclasses,
            "docs_title": self.title,
            "namespaces": self.ontospy_graph.namespaces,
            "stats": self.ontospy_graph.stats(),
            "sources": self.ontospy_graph.sources,
            "ontologies": self.ontospy_graph.all_ontologies,
            "classes": self.ontospy_graph.all_classes,
            "properties": self.ontospy_graph.all_properties,
            "objproperties": self.ontospy_graph.all_properties_object,
            "dataproperties": self.ontospy_graph.all_properties_datatype,
            "annotationproperties":
            self.ontospy_graph.all_properties_annotation,
            "skosConcepts": self.ontospy_graph.all_skos_concepts,
            "instances": []
        }

        return context_data
1367965
@Override
	public OntopOWLConnection getConnection() throws ReasonerInternalException {
		if (!questready) {
			OWLReasonerRuntimeException owlReasonerRuntimeException = new ReasonerInternalException(
					"Ontop was not initialized properly. This is generally indicates, " +
							"connection problems or error during ontology or mapping pre-processing. " +
							"\n\nOriginal error message:\n" + questException.getMessage()) ;
			owlReasonerRuntimeException.setStackTrace(questException.getStackTrace());
			throw owlReasonerRuntimeException;
		}

		try {
			OntopConnection conn = queryEngine.getConnection();
			return new DefaultOntopOWLConnection(conn, inputQueryFactory);
		} catch (OntopConnectionException e) {
			// TODO: find a better exception?
			throw new ReasonerInternalException(e);
		}
	}
1348638
def exhaustive_ontology_ilx_diff_row_only( self, ontology_row: dict ) -> dict:
        '''  '''
        results = []
        header = ['Index'] + list(self.existing_ids.columns)
        for row in self.existing_ids.itertuples():
            row = {header[i]:val for i, val in enumerate(row)}
            check_list = [
                {
                    'external_ontology_row': ontology_row,
                    'ilx_rows': [row],
                },
            ]
            # First layer for each external row. Second is for each potential ilx row. It's simple here 1-1.
            result = self.__exhaustive_diff(check_list)[0][0]
            if result['same']:
                results.append(result)
        return results
760742
def update_ontology(ont_url, rdf_path):
    """"""
    yaml_root = load_yaml_from_url(ont_url)
    G = rdf_graph_from_yaml(yaml_root)
    save_hierarchy(G, rdf_path)
1108575
function(rule, kb) {
        var mappingList = this.getMappings(rule, kb), deferred = q.defer(),
            consequences = [], consequence, causes, iterationConsequences;

        this.checkOperators(rule, mappingList);

        try {
            for (var i = 0; i < mappingList.length; i++) {
                if (mappingList[i]) {
                    // Replace mappings on all consequences
                    causes = Logics.buildCauses(mappingList[i].__facts__);
                    iterationConsequences = [];
                    for (var j = 0; j < rule.consequences.length; j++) {
                        consequence = this.substituteFactVariables(mappingList[i], rule.consequences[j], causes, rule);
                        //if (Logics.filterKnownOrAlternativeImplicitFact(consequence, kb, resolvedImplicitFacts)) {
                        consequences.push(consequence);
                        iterationConsequences.push(consequence);
                        //}
                    }
                    try {
                        Logics.addConsequences(mappingList[i].__facts__, iterationConsequences);
                    } catch(e) {
                        throw "Error when trying to add consequences on the implicit fact.";
                    }
                }
            }
            deferred.resolve(consequences);
        } catch(e) {
            deferred.reject(e);
        }

        return deferred.promise;
    }
636318
private OWLOntology loadOntologyFromURI(URI uri) throws OWLIOException
    {
        try
        {
            return owlOntologyManager.loadOntologyFromOntologyDocument(IRI.create(uri));
        } catch (OWLOntologyCreationException ex)
        {
            throw new OWLIOException(ioErrorMsg, ex);
        }
    }
719324
def parse_owl_rdf(iri):
    
    g = nx.DiGraph(IRI=iri)
    o = Ontospy(iri)

    for cls in o.classes:
        g.add_node(cls.locale, type='Class')

        for parent in cls.parents():
            g.add_edge(cls.locale, parent.locale, type='SubClassOf')

        for instance in cls.instances():
            _, frag = urldefrag(instance)
            g.add_edge(frag, cls.locale, type='ClassAssertion')

    return g
595047
public Set<Pair<Unifier, SemanticDifference>> getMultiUnifierWithSemanticDiff(ReasonerAtomicQuery parent){
        return this.getMultiUnifier(parent, UnifierType.SUBSUMPTIVE).stream()
                .map(u -> new Pair<>(u, this.getAtom().semanticDifference(parent.getAtom(), u)))
                .collect(Collectors.toSet());
    }
312572
def get_ontology(self, id=None, uri=None, match=None):
        

        if not id and not uri and not match:
            return None

        if type(id) == type("string"):
            uri = id
            id = None
            if not is_http(uri):
                match = uri
                uri = None
        if match:
            if type(match) != type("string"):
                return []
            res = []
            for x in self.all_ontologies:
                if match.lower() in x.uri.lower():
                    res += [x]
            return res
        else:
            for x in self.all_ontologies:
                if id and x.id == id:
                    return x
                if uri and x.uri.lower() == uri.lower():
                    return x
            return None