Java 类org.semanticweb.owlapi.model.OWLOntologyStorageException 实例源码

项目:minerva    文件:BlazegraphMolecularModelManager.java   
/**
 * Save a model to the database.
 * 
 * @param m
 * @param annotations
 * @param metadata
 *
 * @throws OWLOntologyStorageException
 * @throws OWLOntologyCreationException
 * @throws IOException
 * @throws RepositoryException 
 * @throws UnknownIdentifierException 
 */
public void saveModel(ModelContainer m,
        Set<OWLAnnotation> annotations, METADATA metadata)
                throws OWLOntologyStorageException, OWLOntologyCreationException,
                IOException, RepositoryException, UnknownIdentifierException {
    IRI modelId = m.getModelId();
    final OWLOntology ont = m.getAboxOntology();
    final OWLOntologyManager manager = ont.getOWLOntologyManager();
    List<OWLOntologyChange> changes = preSaveFileHandler(ont);
    synchronized(ont) {
        try {
            this.writeModelToDatabase(ont, modelId);
            // reset modified flag for abox after successful save
            m.setAboxModified(false);
        } finally {
            if (changes != null) {
                List<OWLOntologyChange> invertedChanges = ReverseChangeGenerator
                        .invertChanges(changes);
                if (invertedChanges != null && !invertedChanges.isEmpty()) {
                    manager.applyChanges(invertedChanges);
                }
            }
        }
    }
}
项目:owltools    文件:OWLHandler.java   
public void topCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException, UnknownOWLClassException {
        if (isHelp()) {
            info("Basic metadata about current ontology"); // TODO - json
            return;
        }
        OntologySetMetadata osmd = new OntologySetMetadata(this.getOWLOntology());
        String manifestVersion = VersionInfo.getManifestVersion("owltools-build-timestamp");
        osmd.serverManifestVersion = manifestVersion == null ? "unknown" : manifestVersion;
        ServerMetadata smd = new ServerMetadata();
        smd.ontologySetMetadata = osmd;
        smd.setMemoryUsage();
        smd.serverManifest = osmd.serverManifestVersion;
//      if (this.getOWLSim() != null) {
//          smd.owlSimMetadata = this.getOWLSim().getMetadata();
//      }
        returnJSON(smd);

    }
项目:owltools    文件:OWLHandler.java   
/**
 * Params: id
 * @throws OWLOntologyCreationException
 * @throws OWLOntologyStorageException
 * @throws IOException
 * @throws OWLParserException
 */
public void getAxiomsCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException, OWLParserException {
    headerOWL();
    boolean direct = getParamAsBoolean(Param.direct, false);
    OWLObject obj = this.resolveEntity();
    LOG.info("finding axioms about: "+obj);
    Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
    if (obj instanceof OWLClass) {
        axioms.addAll(graph.getSourceOntology().getAxioms((OWLClass)obj, Imports.EXCLUDED));
    }
    if (obj instanceof OWLIndividual) {
        axioms.addAll(graph.getSourceOntology().getAxioms((OWLIndividual)obj, Imports.EXCLUDED));
    }
    if (obj instanceof OWLObjectProperty) {
        axioms.addAll(graph.getSourceOntology().getAxioms((OWLObjectProperty)obj, Imports.EXCLUDED));
    }

    for (OWLAxiom ax : axioms) {
        output(ax);
    }
}
项目:owltools    文件:OWLHandler.java   
/**
 * generates a sub-ontology consisting only of classes specified using the id param.
 * If the include_ancestors param is true, then the transitive closure of the input classes is
 * included. otherwise, intermediate classes are excluded and paths are filled.
 * 
 * @throws OWLOntologyCreationException 
 * @throws OWLOntologyStorageException 
 * @throws IOException 
 * @see Mooncat#makeMinimalSubsetOntology(Set, IRI)
 */
public void makeSubsetOntologyCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
    headerOWL();
    Set<OWLClass> objs = resolveClassList();
    Set<OWLClass> tObjs = new HashSet<OWLClass>();
    if (getParamAsBoolean("include_ancestors")) {
        // TODO - more more efficient
        for (OWLClass obj : objs) {
            for (OWLObject t : graph.getAncestorsReflexive(obj)) {
                tObjs.add((OWLClass)t);
            }
        }
    }
    else {
        tObjs = objs;
    }
    Mooncat mooncat;
    mooncat = new Mooncat(graph);
    OWLOntology subOnt = 
            mooncat.makeMinimalSubsetOntology(tObjs,
                    IRI.create("http://purl.obolibrary.org/obo/temporary"));
    for (OWLAxiom axiom : subOnt.getAxioms()) {
        output(axiom); // TODO
    }
    graph.getManager().removeOntology(subOnt);
}
项目:owltools    文件:OWLHandler.java   
/**
 * tests which of a set of input classes (specified using id) is applicable for a set of taxa
 * (specified using taxid)
 * 
 * @throws OWLOntologyCreationException 
 * @throws OWLOntologyStorageException 
 * @throws IOException 
 */
public void isClassApplicableForTaxonCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
    headerOWL();
    TaxonConstraintsEngine tce = new TaxonConstraintsEngine(graph);
    Set<OWLClass> testClsSet = resolveClassList();
    Set<OWLClass> testTaxSet = resolveClassList(Param.taxid);
    for (OWLClass testTax : testTaxSet) {
        Set<OWLObject> taxAncs = graph.getAncestorsReflexive(testTax);
        LOG.info("Tax ancs: "+taxAncs);
        for (OWLClass testCls : testClsSet) {
            Set<OWLGraphEdge> edges = graph.getOutgoingEdgesClosure(testCls);
            boolean isOk = tce.isClassApplicable(testCls, testTax, edges, taxAncs);
            // TODO - other formats
            output(testCls);
            print("\t");
            output(testTax);
            outputLine("\t"+isOk);
        }
    }
}
项目:owltools    文件:OWLHandler.java   
public void getSimilarClassesCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException {
    if (isHelp()) {
        info("Returns semantically similar classes using OWLSim2");
        return;
    }
    headerOWL();
    OWLClass a = this.resolveClass();
    OwlSim sos = getOWLSim();
    List<ScoreAttributeSetPair> saps = new ArrayList<ScoreAttributeSetPair>();
    for (OWLClass b : this.getOWLOntology().getClassesInSignature()) {
        double score = sos.getAttributeJaccardSimilarity(a, b);
        saps.add(new ScoreAttributeSetPair(score, b) );
    }
    Collections.sort(saps);
    int limit = 100;

    int n=0;
    for (ScoreAttributeSetPair sap : saps) {
        output(sap.getArbitraryAttributeClass());
        this.outputLine("score="+sap.score); // todo - jsonify
        n++;
        if (n > limit) {
            break;
        }
    }
}
项目:owltools    文件:OWLHandler.java   
public void getLowestCommonSubsumersCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException {
    if (isHelp()) {
        info("Returns LCSs using sim2");
        return;
    }
    headerOWL();
    OwlSim sos = getOWLSim();

    Set<OWLObject> objs = this.resolveEntityList();
    if (objs.size() == 2) {
        Iterator<OWLObject> oit = objs.iterator();
        OWLClass a = (OWLClass) oit.next();
        OWLClass b = (OWLClass) oit.next();
        Set<Node<OWLClass>> lcsNodes = sos.getNamedCommonSubsumers(a, b);
        for (Node<OWLClass> n : lcsNodes) {
            for (OWLClass c : n.getEntities()) {
                output(c);
            }
        }
    }
    else {
        // TODO - throw
    }
}
项目:owltools    文件:OWLHandler.java   
@Deprecated
public void deleteFactCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException {
    if (isHelp()) {
        info("generates ClassAssertion");
        return;
    }
    OWLOntology ont = resolveOntology(Param.ontology);
    OWLIndividual i = resolveIndividual(Param.individualId);
    OWLIndividual j = resolveIndividual(Param.fillerId);
    OWLObjectProperty p = resolveObjectProperty(Param.propertyId);
    for (OWLObjectPropertyAssertionAxiom ax : ont.getAxioms(AxiomType.OBJECT_PROPERTY_ASSERTION)) {
        if (ax.getSubject().equals(i)) {
            if (p == null || ax.getProperty().equals(p)) {
                if (j == null || ax.getObject().equals(j)) {
                    removeAxiom(ont, graph.getDataFactory().getOWLObjectPropertyAssertionAxiom(p, i, j));
                }
            }
        }
    }
    String jsonStr = "";
    response.getWriter().write(jsonStr);
}
项目:owltools    文件:OWLHandler.java   
public void printCachedObjects() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
    if (getFormat().equals("json")) {
        OWLGsonRenderer jsonp = new OWLGsonRenderer(response.getWriter());
        if (cachedObjects.size() > 0) {
            jsonp.render(cachedObjects);
        }
        else {
            jsonp.render(cachedAxioms);
        }
    }
    else {
        // ontology format
        if (cachedAxioms.size() == 0)
            return;
        OWLOntology tmpOnt = getTemporaryOntology();
        graph.getManager().addAxioms(tmpOnt, cachedAxioms);
        OWLDocumentFormat ofmt = getOWLOntologyFormat();
        LOG.info("Format:"+ofmt);
        ParserWrapper pw = new ParserWrapper();
        //graph.getManager().saveOntology(tmpOnt, ofmt, response.getOutputStream());
        pw.saveOWL(tmpOnt, ofmt, response.getOutputStream());
        graph.getManager().removeOntology(tmpOnt);
        cachedAxioms = new HashSet<OWLAxiom>();
    }
}
项目:owltools    文件:OldSimpleOwlSim.java   
/**
 * generates view ontologies and pre-computes all LCSs.
 * These are added to the source ontology
 * 
 * @throws OWLOntologyCreationException
 * @throws OWLOntologyStorageException 
 * @throws FileNotFoundException 
 */

@Deprecated
public void generateGroupingClasses() throws OWLOntologyCreationException, FileNotFoundException, OWLOntologyStorageException {
    createElementAttributeMapFromOntology();
    removeUnreachableAxioms();

    generateSourcePropertyViews();
    generatePropertyViews();
    this.saveOntology(Stage.VIEW);

    makeAllByAllLowestCommonSubsumer();
    this.saveOntology(Stage.LCS);
    attributeElementCount = null;

    reason();
}
项目:owltools    文件:ExhaustiveSimPreProcessorTest.java   
@Test
public void exhaustiveTestOnGO() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, MathException {
    /*
    ParserWrapper pw = new ParserWrapper();
    sourceOntol = pw.parseOBO(getResourceIRIString("go-subset-t1.obo"));
    g = new OWLGraphWrapper(sourceOntol);
    IRI vpIRI = g.getOWLObjectPropertyByIdentifier("GOTESTREL:0000001").getIRI();
    TableToAxiomConverter ttac = new TableToAxiomConverter(g);
    ttac.config.axiomType = AxiomType.CLASS_ASSERTION;
    ttac.config.property = vpIRI;
    ttac.config.isSwitchSubjectObject = true;
    ttac.parse("src/test/resources/simplegaf-t1.txt");

    OWLPrettyPrinter pp = new OWLPrettyPrinter(g);

    AutomaticSimPreProcessor pproc = new AutomaticSimPreProcessor();
    pproc.setInputOntology(sourceOntol);
    pproc.setOutputOntology(sourceOntol);
    pproc.preprocess();
    */
}
项目:owltools    文件:ParserWrapper.java   
public void saveOWL(OWLOntology ont, OWLDocumentFormat owlFormat, String file) throws OWLOntologyStorageException, IOException {
    if ((owlFormat instanceof OBODocumentFormat) ||
            (owlFormat instanceof OWLOboGraphsFormat) || 
            (owlFormat instanceof OWLOboGraphsYamlFormat) || 
            (owlFormat instanceof OWLJSONFormat) || 
            (owlFormat instanceof OWLJsonLDFormat)){
        try {
            FileOutputStream os = new FileOutputStream(new File(file));
            saveOWL(ont, owlFormat, os);
        } catch (FileNotFoundException e) {
            throw new OWLOntologyStorageException("Could not open file: "+file, e);
        }
    }
    else {
        IRI iri;
        if (file.startsWith("file://")) {
            iri = IRI.create(file);
        }
        else {
            iri = IRI.create(new File(file));
        }
        manager.saveOntology(ont, owlFormat, iri);
    }
}
项目:owltools    文件:OboOntologyReleaseRunner.java   
private void createModule(String ontologyId, String moduleName, Set<OWLEntity> signature)
        throws OWLOntologyCreationException, IOException, OWLOntologyStorageException 
{
    // create a new manager, avoid unnecessary change events
    final OWLOntologyManager m = OWLManager.createOWLOntologyManager();

    // extract module
    SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, mooncat.getOntology(), ModuleType.BOT);
    Set<OWLAxiom> moduleAxioms = sme.extract(signature);

    OWLOntology module = m.createOntology(IRI.generateDocumentIRI());
    m.addAxioms(module, moduleAxioms);

    // save module
    OutputStream moduleOutputStream = null;
    try {
        moduleOutputStream = getOutputSteam(getModuleFileName(ontologyId, moduleName));
        m.saveOntology(module, moduleOutputStream);
    }
    finally {
        IOUtils.closeQuietly(moduleOutputStream);
    }
}
项目:owltools    文件:AssertInferenceTool.java   
private static void createModule(String moduleName, Set<OWLEntity> signature, OWLOntology ont)
        throws OWLOntologyCreationException, IOException, OWLOntologyStorageException 
{
    // create a new manager avoid unnecessary change events
    final OWLOntologyManager m = OWLManager.createOWLOntologyManager();

    // extract module
    SyntacticLocalityModuleExtractor sme = new SyntacticLocalityModuleExtractor(m, ont, ModuleType.BOT);
    Set<OWLAxiom> moduleAxioms = sme.extract(signature);

    OWLOntology module = m.createOntology(IRI.generateDocumentIRI());
    m.addAxioms(module, moduleAxioms);

    // save module
    OutputStream moduleOutputStream = null;
    try {
        moduleOutputStream = new FileOutputStream(getModuleFile(moduleName));
        m.saveOntology(module, moduleOutputStream);
    }
    finally {
        IOUtils.closeQuietly(moduleOutputStream);
    }
}
项目:owltools    文件:NCBI2OWL.java   
/**
 * Read a data file, create an OWL representation, and save an OWL file.
 * Create alternate identifiers from the merge.dmp file information
 *
 * @param inputPath the path to the input data file (e.g. taxonomy.dat)
 * @param outputPath the path to the output OWL file
 *  (e.g. ncbi_taxonomy.owl).
 * @param mergeInfo the input stream of the merged information
 * @param citationInfo the input stream of the citation information
 * @param uniqueNames
 * @return OWL ontology
 * @throws IOException if the paths do not resolve
 * @throws OWLOntologyCreationException if OWLAPI fails to create an
 *  empty ontology
 * @throws OWLOntologyStorageException if OWLAPI can't save the file
 */
public static OWLOntology convertToOWL(String inputPath,
        String outputPath, InputStream mergeInfo,
        InputStream citationInfo,
        Map<String, String> uniqueNames) throws IOException,
        OWLOntologyCreationException,
        OWLOntologyStorageException {
    File outputFile = new File(outputPath);
    IRI outputIRI = IRI.create(outputFile);
    OWLOntology ontology = convertToOWL(inputPath, uniqueNames);

    if (mergeInfo != null) {
        addAltIds(ontology, mergeInfo);
    }

    if (citationInfo != null) {
        addCitationInfo(ontology, citationInfo);
    }

    logger.debug("Saving ontology...");

    ontology.getOWLOntologyManager().saveOntology(
        ontology, outputIRI);
    return ontology;
}
项目:Widoco    文件:LODEGeneration.java   
/**
         * Method that uses the loaded ontology and parses it in case there are imports that have not been considered
         * @param considerImportedOntologies
         * @param manager
         * @param ontology
         * @return
         * @throws OWLOntologyCreationException
         * @throws OWLOntologyStorageException
         * @throws URISyntaxException 
         */
    private static String parseImports(
                        boolean considerImportedOntologies, 
                        OWLOntologyManager manager,
                        OWLOntology ontology) 
    throws OWLOntologyCreationException, OWLOntologyStorageException, URISyntaxException {
            String result = "";
            if (considerImportedOntologies) {
                //considerImportedClosure || //<- removed for the moment
                Set<OWLOntology> setOfImportedOntologies = new HashSet<OWLOntology>();
                setOfImportedOntologies.addAll(ontology.getDirectImports());
//                else {
//                        setOfImportedOntologies.addAll(ontology.getImportsClosure());
//                }
                for (OWLOntology importedOntology : setOfImportedOntologies) {
                        manager.addAxioms(ontology, importedOntology.getAxioms());
                }
            }
            OWLOntologyDocumentTarget parsedOntology = new StringDocumentTarget();
            manager.saveOntology(ontology,new RDFXMLDocumentFormat(), parsedOntology);
            result = parsedOntology.toString();
//      }

            return result;
    }
项目:OntoBench    文件:OntologyHttpMessageConverter.java   
@Override
protected void writeInternal(OWLOntology ontology, HttpOutputMessage httpOutputMessage)
    throws IOException, HttpMessageNotWritableException {
  OWLOntologyDocumentTarget target = new StringDocumentTarget();

  try {
    ontology.saveOntology(documentFormat, target);
  } catch (OWLOntologyStorageException e) {
    // should not happpen
    throw new IllegalStateException(e);
  }

  httpOutputMessage.getBody().write(target.toString().getBytes());
}
项目:minerva    文件:CoreMolecularModelManager.java   
/**
 * Export the ABox, will try to set the ontologyID to the given modelId (to
 * ensure import assumptions are met)
 * 
 * @param model
 * @param ontologyFormat
 * @return modelContent
 * @throws OWLOntologyStorageException
 */
public String exportModel(ModelContainer model, OWLDocumentFormat ontologyFormat) throws OWLOntologyStorageException {
    final OWLOntology aBox = model.getAboxOntology();
    final OWLOntologyManager manager = aBox.getOWLOntologyManager();

    // make sure the exported ontology has an ontologyId and that it maps to the modelId
    final IRI expectedABoxIRI = model.getModelId();
    Optional<IRI> currentABoxIRI = aBox.getOntologyID().getOntologyIRI();
    if (currentABoxIRI.isPresent() == false) {
        manager.applyChange(new SetOntologyID(aBox, expectedABoxIRI));
    }
    else {
        if (expectedABoxIRI.equals(currentABoxIRI) == false) {
            OWLOntologyID ontologyID = new OWLOntologyID(Optional.of(expectedABoxIRI), Optional.of(expectedABoxIRI));
            manager.applyChange(new SetOntologyID(aBox, ontologyID));
        }
    }

    // write the model into a buffer
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    if (ontologyFormat != null) {
        manager.saveOntology(aBox, ontologyFormat, outputStream);
    }
    else {
        manager.saveOntology(aBox, outputStream);
    }

    // extract the string from the buffer
    String modelString = outputStream.toString();
    return modelString;
}
项目:Source    文件:ParserMain.java   
/**
 * Enrich ontology with a given parse result at hand.
 * Static method needed for Web interface
 * @throws OWLOntologyStorageException 
 */
public static void enrichOntologyWithSingleParseResult(ParseResult p, OntoModel ontModel, String outputDirectoryPath, boolean useRealReasoner) throws OWLOntologyStorageException {
    if (ontModel!=null) {
        p.getDLTree().doOntologyEnrichment(ontModel, outputDirectoryPath, useRealReasoner);
    }
    else {
        throw new RuntimeException("The input ontology to enrich is not specified.");
    }
}
项目:elk-reasoner    文件:SavingInferredAxioms.java   
public static void main(String[] args) throws OWLOntologyStorageException,
        OWLOntologyCreationException {
    OWLOntologyManager inputOntologyManager = OWLManager.createOWLOntologyManager();
    OWLOntologyManager outputOntologyManager = OWLManager.createOWLOntologyManager();

    // Load your ontology.
    OWLOntology ont = inputOntologyManager.loadOntologyFromOntologyDocument(new File("path-to-ontology"));

    // Create an ELK reasoner.
    OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
    OWLReasoner reasoner = reasonerFactory.createReasoner(ont);

    // Classify the ontology.
    reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);

    // To generate an inferred ontology we use implementations of
    // inferred axiom generators
    List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
    gens.add(new InferredSubClassAxiomGenerator());
    gens.add(new InferredEquivalentClassAxiomGenerator());

    // Put the inferred axioms into a fresh empty ontology.
    OWLOntology infOnt = outputOntologyManager.createOntology();
    InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner,
            gens);
    iog.fillOntology(outputOntologyManager.getOWLDataFactory(), infOnt);

    // Save the inferred ontology.
    outputOntologyManager.saveOntology(infOnt,
            new FunctionalSyntaxDocumentFormat(),
            IRI.create((new File("path-to-output").toURI())));

    // Terminate the worker threads used by the reasoner.
    reasoner.dispose();
}
项目:elk-reasoner    文件:IncrementalClassification.java   
public static void main(String[] args) throws OWLOntologyStorageException,
        OWLOntologyCreationException {
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

    // Load your ontology
    OWLOntology ont = manager.loadOntologyFromOntologyDocument(new File("path-to-ontology"));

    // Create an ELK reasoner.
    OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
    OWLReasoner reasoner = reasonerFactory.createReasoner(ont);

    // Classify the ontology.
    reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);

    OWLDataFactory factory = manager.getOWLDataFactory();
    OWLClass subClass = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#AbsoluteShapeState"));
    OWLAxiom removed = factory.getOWLSubClassOfAxiom(subClass, factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#ShapeState")));

    OWLAxiom added = factory.getOWLSubClassOfAxiom(subClass, factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#GeneralisedStructure")));
    // Remove an existing axiom, add a new axiom
    manager.addAxiom(ont, added);
    manager.removeAxiom(ont, removed);
    // This is a buffering reasoner, so you need to flush the changes
    reasoner.flush();

    // Re-classify the ontology, the changes should be accommodated
    // incrementally (i.e. without re-inferring all subclass relationships)
    // You should be able to see it from the log output
    reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);       

    // Terminate the worker threads used by the reasoner.
    reasoner.dispose();
}
项目:owltools    文件:OWLHandler.java   
public void memCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException, UnknownOWLClassException {
    if (isHelp()) {
        info("Basic metadata about current ontology"); // TODO - json
        return;
    }
    ServerMetadata smd = new ServerMetadata();
    smd.setMemoryUsage();
    response.getWriter().write("Used: "+smd.memoryUsedInKB);
}
项目:owltools    文件:OWLHandler.java   
/**
 * Params: direct
 * @throws OWLOntologyCreationException
 * @throws OWLOntologyStorageException
 * @throws IOException
 */
public void allSubClassOfCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
    headerOWL();
    boolean direct = getParamAsBoolean(Param.direct, true);
    OWLReasoner r = getReasoner();
    for (OWLClass c : getOWLOntology().getClassesInSignature(Imports.INCLUDED)) {
        for (OWLClass sc : r.getSuperClasses(c, direct).getFlattened()) {
            output(graph.getDataFactory().getOWLSubClassOfAxiom(c, sc));
        }
    }
}
项目:owltools    文件:OWLHandler.java   
public void getOutgoingEdgesCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException {
    if (isHelp()) {
        info("Returns paths to reachable nodes in ontology graph");
        return;
    }
    headerOWL();
    boolean isClosure = getParamAsBoolean("closure", true);
    boolean isReflexive = getParamAsBoolean("reflexive", true);
    OWLObject obj = this.resolveEntity();
    LOG.info("finding edges from: "+obj);
    for (OWLGraphEdge e : graph.getOutgoingEdges(obj,isClosure,isReflexive)) {
        output(e);
    }
}
项目:owltools    文件:OWLHandler.java   
public void classCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
    if (isHelp()) {
        info("Returns json object describing a class");
        return;
    }
    String id = this.getParam(Param.id);
    OWLClass cls = graph.getOWLClassByIdentifier(id);
    FrameMakerLD fm = new FrameMakerLD(graph);
    ClassFrameLD f = fm.makeClassFrame(cls);
    returnJSON(f);
}
项目:owltools    文件:OWLHandler.java   
/**
 * visualize using QuickGO graphdraw. 
 * 
 * @throws OWLOntologyCreationException 
 * @throws OWLOntologyStorageException 
 * @throws IOException 
 */
public void qvizCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException {
    String fmt = "png";
    headerImage(fmt);
    GraphicsConfig gfxCfg = new GraphicsConfig();
    Set<OWLObject> objs = resolveEntityList();
    OWLGraphLayoutRenderer r = new OWLGraphLayoutRenderer(graph);
    r.graphicsConfig = gfxCfg;

    r.addObjects(objs);
    r.renderImage(fmt, response.getOutputStream());
}
项目:owltools    文件:OWLHandler.java   
public void getOwlSimMetadataCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException, UnknownOWLClassException {
    if (isHelp()) {
        info("Basic metadata about current owlsim instance"); // TODO - json
        return;
    }
    OwlSimMetadata osmd = getOWLSim().getMetadata();
    returnJSON(osmd);
}
项目:owltools    文件:OWLHandler.java   
public void getSimilarIndividualsCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException {
    if (isHelp()) {
        info("Returns matching individuals using OWLSim2");
        return;
    }
    headerOWL();
    OWLNamedIndividual i = (OWLNamedIndividual) this.resolveEntity();
    LOG.info("i="+i);
    if (i == null) {
        LOG.error("Could not resolve id");
        // TODO - throw
        return;
    }
    OwlSim sos = getOWLSim();
    List<ScoreAttributeSetPair> saps = new Vector<ScoreAttributeSetPair>();
    for (OWLNamedIndividual j : this.getOWLOntology().getIndividualsInSignature()) {
        // TODO - make configurable
        ScoreAttributeSetPair match = sos.getSimilarityMaxIC(i, j);
        saps.add(match);
    }
    Collections.sort(saps);
    int limit = 100; // todo - configurable

    int n=0;
    for (ScoreAttributeSetPair sap : saps) {
        //output(sap.attributeClass); TODO
        this.outputLine("score="+sap.score); // todo - jsonify
        n++;
        if (n > limit) {
            break;
        }
    }
}
项目:owltools    文件:OWLHandler.java   
public void getAnnotationSufficiencyScoreCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException {
    if (isHelp()) {
        info("Specificity score for a set of annotations");
        return;
    }
    headerText();
    OwlSim sos = getOWLSim();
    Set<OWLClass> atts = this.resolveClassList(Param.a);
    LOG.info("Calculating AnnotationSufficiency score for "+atts.toString());
    SimJSONEngine sj = new SimJSONEngine(graph,sos);
    String jsonStr = sj.getAnnotationSufficiencyScore(atts);
    LOG.info("Finished getAnnotationSufficiencyScore");
    response.setContentType("application/json");
    response.getWriter().write(jsonStr);
}
项目:owltools    文件:OWLHandler.java   
@Deprecated
public void assertTypeCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException {
    if (isHelp()) {
        info("generates ClassAssertion");
        return;
    }
    OWLOntology ont = resolveOntology(Param.ontology);
    OWLClass c = resolveClass(Param.classId);
    OWLIndividual i = resolveIndividual(Param.individualId);
    addAxiom(ont, graph.getDataFactory().getOWLClassAssertionAxiom(c, i));
    String jsonStr = "";
    response.getWriter().write(jsonStr);
}
项目:owltools    文件:OWLHandler.java   
@Deprecated
public void assertFactCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException {
    if (isHelp()) {
        info("generates ClassAssertion");
        return;
    }
    OWLOntology ont = resolveOntology(Param.ontology);
    OWLIndividual i = resolveIndividual(Param.individualId);
    OWLIndividual j = resolveIndividual(Param.fillerId);
    OWLObjectProperty p = resolveObjectProperty(Param.propertyId);
    addAxiom(ont, graph.getDataFactory().getOWLObjectPropertyAssertionAxiom(p, i, j));
    String jsonStr = "";
    response.getWriter().write(jsonStr);
}
项目:owltools    文件:OWLHandler.java   
public void assertEnabledByCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException {
    if (isHelp()) {
        info("generates ClassAssertion");
        return;
    }
    OWLOntology ont = resolveOntology(Param.ontology);
    OWLIndividual i = resolveIndividual(Param.individualId);
    OWLClass j = resolveClass(Param.fillerId);
    OWLObjectProperty p = 
            OBOUpperVocabulary.GOREL_enabled_by.getObjectProperty(graph.getDataFactory());
    addSomeValuesFromClassAssertion(ont, i, j, p);
    String jsonStr = "";
    response.getWriter().write(jsonStr);
}
项目:owltools    文件:OWLHandler.java   
public void assertOccursInCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException {
    if (isHelp()) {
        info("generates ClassAssertion");
        return;
    }
    OWLOntology ont = resolveOntology(Param.ontology);
    OWLIndividual i = resolveIndividual(Param.individualId);
    OWLClass j = resolveClass(Param.fillerId);
    OWLObjectProperty p = 
            OBOUpperVocabulary.BFO_occurs_in.getObjectProperty(graph.getDataFactory());
    addSomeValuesFromClassAssertion(ont, i, j, p);
    String jsonStr = "";
    response.getWriter().write(jsonStr);
}
项目:owltools    文件:OWLRenderer.java   
@Override
public void dispose() {
    try {
        graph.getManager().saveOntology(ontology, resultOutStream);
    } catch (OWLOntologyStorageException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}
项目:owltools    文件:PhenoSimHQETest.java   
@Test
public void testPhenoSim() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, MathException {
    ParserWrapper pw = new ParserWrapper();
    sourceOntol = pw.parseOWL(getResourceIRIString("q-in-e.omn"));
    g =  new OWLGraphWrapper(sourceOntol);
     owlpp = new OWLPrettyPrinter(g);

    // assume buffering
    OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol);
    try {
        pproc = new PhenoSimHQEPreProcessor();
        pproc.setInputOntology(sourceOntol);
        pproc.setOutputOntology(sourceOntol);
        pproc.setReasoner(reasoner);
        pproc.setOWLPrettyPrinter(owlpp);
        ((PhenoSimHQEPreProcessor)pproc).defaultLCSElementFrequencyThreshold = 0.7;

        //sos.setSimPreProcessor(pproc);
        //sos.preprocess();
        pproc.preprocess();
        reasoner.flush();

        sos = new SimpleOwlSim(sourceOntol);
        sos.setSimPreProcessor(pproc);
        sos.createElementAttributeMapFromOntology();

        //sos.saveOntology("/tmp/z.owl");

        reasoner.flush();
        for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) {
            for (OWLNamedIndividual j : sourceOntol.getIndividualsInSignature()) {
                showSim(i,j);
            }
        }
    }
    finally {
        reasoner.dispose();
    }
}
项目:owltools    文件:PhenoSimHQETest.java   
@Test
public void testPhenoSimMouse() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, MathException {
    ParserWrapper pw = new ParserWrapper();
    sourceOntol = pw.parseOWL(getResourceIRIString("test_phenotype.owl"));
    g =  new OWLGraphWrapper(sourceOntol);
     owlpp = new OWLPrettyPrinter(g);

    // assume buffering
    OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol);
    try {
        pproc = new PhenoSimHQEPreProcessor();
        pproc.setInputOntology(sourceOntol);
        pproc.setOutputOntology(sourceOntol);
        pproc.setReasoner(reasoner);
        pproc.setOWLPrettyPrinter(owlpp);
        ((PhenoSimHQEPreProcessor)pproc).defaultLCSElementFrequencyThreshold = 0.7;

        //sos.setSimPreProcessor(pproc);
        //sos.preprocess();
        pproc.preprocess();
        reasoner.flush();

        sos = new SimpleOwlSim(sourceOntol);
        sos.setSimPreProcessor(pproc);
        sos.createElementAttributeMapFromOntology();

        //sos.saveOntology("/tmp/z.owl");

        reasoner.flush();
        for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) {
            for (OWLNamedIndividual j : sourceOntol.getIndividualsInSignature()) {
                showSim(i,j);
            }
        }
    }
    finally {
        reasoner.dispose();
    }
}
项目:owltools    文件:BasicOWLSimTestUsingSOS.java   
@Test
public void testBasicSim() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, MathException, UnknownOWLClassException {
    ParserWrapper pw = new ParserWrapper();
    sourceOntol = pw.parseOWL(getResourceIRIString("sim/mp-subset-1.obo"));
    g =  new OWLGraphWrapper(sourceOntol);
    parseAssociations(getResource("sim/mgi-gene2mp-subset-1.tbl"), g);

    owlpp = new OWLPrettyPrinter(g);

    // assume buffering
    OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(sourceOntol);
    try {

        owlsim = new SimpleOwlSim(sourceOntol);
        ((SimpleOwlSim) owlsim).setReasoner(reasoner);
        LOG.info("Reasoner="+owlsim.getReasoner());

        //sos.saveOntology("/tmp/z.owl");

        reasoner.flush();
        for (OWLNamedIndividual i : sourceOntol.getIndividualsInSignature()) {
            //System.out.println("COMPARING: "+i);
            for (OWLNamedIndividual j : sourceOntol.getIndividualsInSignature()) {
                showSimOld(i,j);
            }
        }
    }
    finally {
        reasoner.dispose();
    }
}
项目:owltools    文件:BridgeExtractor.java   
public void save(String fn, OWLDocumentFormat format, OWLOntology xo) throws FileNotFoundException, OWLOntologyStorageException {
    fn = fn + "." + getSuffix(format);
    File file = new File(fn);
    file.getParentFile().mkdirs();
    OutputStream os = new FileOutputStream(file);
    LOG.info("Saving: "+xo);
    ontology.getOWLOntologyManager().saveOntology(xo, format, os);
}
项目:owltools    文件:ImportClosureSlurper.java   
public void save(String base, String file) throws IOException, OWLOntologyStorageException {
    if (file == null) {
        save(base);
        return;
    }
    File baseFolder =  new File(base).getCanonicalFile();
    FileOutputStream os = null;
    try {
        os = new FileOutputStream(new File(baseFolder, file));
        save(baseFolder, os);
    }finally {
        IOUtils.closeQuietly(os);
    }
}
项目:owltools    文件:EquivalenceSetMergeUtilTest.java   
@Test
public void testMerge() throws OWLOntologyCreationException, IOException, IncoherentOntologyException, OWLOntologyStorageException {
    ParserWrapper pw = new ParserWrapper();
    OWLGraphWrapper g =
            pw.parseToOWLGraph(getResourceIRIString("equivalence-set-merge-util-test.obo"));
    OWLOntology ont1 = g.getSourceOntology();
    ElkReasonerFactory rf = new ElkReasonerFactory();
    OWLReasoner reasoner = rf.createReasoner(ont1);
    EquivalenceSetMergeUtil esmu = new EquivalenceSetMergeUtil(g, reasoner);
    esmu.setPrefixScore("A", 8.0);
    esmu.setPrefixScore("B", 6.0);
    esmu.setPrefixScore("C", 4.0);
    OWLAnnotationProperty lp = g.getDataFactory().getOWLAnnotationProperty( OWLRDFVocabulary.RDFS_LABEL.getIRI() );
    esmu.setPropertyPrefixScore( lp, "C", 5.0);
    esmu.setPropertyPrefixScore( lp, "B", 4.0);
    esmu.setPropertyPrefixScore( lp, "A", 3.0);

    OWLAnnotationProperty dp = g.getDataFactory().getOWLAnnotationProperty( Obo2OWLVocabulary.IRI_IAO_0000115.getIRI() );
    esmu.setPropertyPrefixScore( dp, "B", 5.0);
    esmu.setPropertyPrefixScore( dp, "A", 4.0);
    esmu.setPropertyPrefixScore( dp, "C", 3.0);

    esmu.setRemoveAxiomatizedXRefs(true);

    esmu.merge();
    OWLDocumentFormat fmt = new OBODocumentFormat();
    pw.saveOWL(g.getSourceOntology(), "target/esmu.owl");
    //pw.setCheckOboDoc(false);
    pw.saveOWL(g.getSourceOntology(), fmt, "target/esmu.obo");

    OWLOntology ont2 = pw.parseOWL(getResourceIRIString("equivalence-set-merge-util-expected.obo"));
    assertEquals(0, compare(ont1, ont2));
}