当前位置: 首页>>代码示例>>Java>>正文


Java OntModel.add方法代码示例

本文整理汇总了Java中org.apache.jena.ontology.OntModel.add方法的典型用法代码示例。如果您正苦于以下问题:Java OntModel.add方法的具体用法?Java OntModel.add怎么用?Java OntModel.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.jena.ontology.OntModel的用法示例。


在下文中一共展示了OntModel.add方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: inferClasses

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
@Override
public Set<URI> inferClasses(final URI uri, final WebResource resource, final Ontology ontology) {

    final OntModel model = resolveImports(ont(ontology));
    model.add(parse(resource));

    final Individual individual = model.getIndividual(uri.toString());

    if (individual != null) {
        return individual
                .listRDFTypes(false)
                .filterKeep(Resource::isURIResource)
                .mapWith(Resource::getURI)
                .mapWith(URI::create)
                .toSet();
    } else {
        LOG.info("<{}> does not make any statements about itself, " +
                "so we can't infer anything about it nor bind extensions to it", uri);
        return Collections.emptySet();
    }

}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-api-x,代码行数:23,代码来源:JenaOntologyService.java

示例2: fixOntModel

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
public OntModel fixOntModel(OntModel ontModel)
    {
        if (ontModel == null) throw new IllegalArgumentException("Model cannot be null");
        
        OntModel fixedModel = ModelFactory.createOntologyModel(ontModel.getSpecification());
        Query fix = QueryFactory.create("CONSTRUCT\n" +
"{\n" +
"  ?s ?p ?o\n" +
"}\n" +
"WHERE\n" +
"{\n" +
"  ?s ?p ?o\n" +
"  FILTER (!(?p = <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> && ?o = <https://www.w3.org/ns/ldt#Constraint>))\n" +
"}");
        
        try (QueryExecution qex = QueryExecutionFactory.create(fix, ontModel))
        {
            fixedModel.add(qex.execConstruct());
        }
        
        return fixedModel;
    }
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:23,代码来源:Validator.java

示例3: resolveImports

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
/** Resolve the closure of all owl:imports statements into a union model */
private OntModel resolveImports(final OntModel model) {

    // if no imports, nothing to resolve
    if (model.listObjectsOfProperty(model.getProperty(OWL_IMPORTS)).toSet().isEmpty()) {
        return model;
    }

    final OntModel out = ModelFactory.createOntologyModel(defaultSpec, model.getBaseModel());

    final Set<String> resolvedImports = new HashSet<>();
    Set<String> unresolvedImports = imports(model, resolvedImports);

    while (!unresolvedImports.isEmpty()) {

        for (final String unresolved : unresolvedImports) {
            model.add(load(unresolved));
            resolvedImports.add(unresolved);

        }
        unresolvedImports = imports(model, resolvedImports);
    }

    // Since we manually resolved all imports, remove all owl:imports statements
    out.removeAll(null, model.getProperty(OWL_IMPORTS), null);

    return out;
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-api-x,代码行数:29,代码来源:JenaOntologyService.java

示例4: merge

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
@Override
public Ont merge(final Ontology ontology1, final Ontology ontology2) {
    final OntModel model = ModelFactory.createOntologyModel(defaultSpec);

    model.add(ont(ontology1).getBaseModel());
    model.add(ont(ontology2).getBaseModel());

    return new Ont(model);
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-api-x,代码行数:10,代码来源:JenaOntologyService.java

示例5: OntologyProvider

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
public OntologyProvider(final OntDocumentManager ontDocumentManager, final String ontologyURI,
        final OntModelSpec ontModelSpec, final boolean materialize)
{
    super(Ontology.class);
    
    if (ontDocumentManager == null) throw new IllegalArgumentException("OntDocumentManager cannot be null");        
    if (ontologyURI == null) throw new IllegalArgumentException("URI cannot be null");
    if (ontModelSpec == null) throw new IllegalArgumentException("OntModelSpec cannot be null");
    
    this.ontDocumentManager = ontDocumentManager;
    this.ontologyURI = ontologyURI;
    
    // materialize OntModel inferences to avoid invoking rules engine on every request
    if (materialize && ontModelSpec.getReasoner() != null)
    {
        OntModel infModel = getOntModel(ontDocumentManager, ontologyURI, ontModelSpec);
        Ontology ontology = infModel.getOntology(ontologyURI);

        ImportCycleChecker checker = new ImportCycleChecker();
        checker.check(ontology);
        if (checker.getCycleOntology() != null)
        {
            if (log.isErrorEnabled()) log.error("Sitemap contains an ontology which forms an import cycle: {}", checker.getCycleOntology());
            throw new OntologyException("Sitemap contains an ontology which forms an import cycle: " + checker.getCycleOntology().getURI());
        }
        
        OntModel materializedModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
        materializedModel.add(infModel);
        ontDocumentManager.addModel(ontologyURI, materializedModel, true);
    }
}
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:32,代码来源:OntologyProvider.java

示例6: toOWL

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
/** translate the included schema to OWL and include it  */

	public void toOWL(OntModel ont, File target, String location, Context ctx) throws Exception {
		try {
			// redefined simple types
			for (int i=0; simpleType!=null && i<simpleType.length; i++)
				simpleType[i].toOWL(ctx);
			// redefined complex types
			for (int i=0; complexType!=null && i<complexType.length; i++)
				complexType[i].toOWL(null,false,ctx);
			// groups
			for (int i=0; group!=null && i<group.length; i++)
				group[i].toOWL(null,1,1,ctx);
			// attribute groups
			for (int i=0; attributeGroup!=null && i<attributeGroup.length; i++)
				attributeGroup[i].toOWL(null,ctx);
			
			// map included schema
			String suffix = ctx.getLang().toLowerCase().equals("n3")?"n3":"owl";
			String loc = changeSuffix(schemaLocation, suffix);
			URI base = prune(ctx.getBaseMap().resolve(location)).resolve(loc);
			Context c = ctx.copy();
			c.setBase(base);
			
			if (target!=null) {
				File t = target.getCanonicalFile();
				if (!t.isDirectory()) t = t.getParentFile();
				ont.add(_schema.toOWL(new File(t,loc),base.toString(),true, c).getBaseModel());
			}
			else ont.add(_schema.toOWL((File)null,base.toString(),true, c).getBaseModel());
		}
		catch (Exception e) {
			e.printStackTrace(System.err);
		}
	}
 
开发者ID:stevebattle,项目名称:Gloze,代码行数:36,代码来源:redefine.java

示例7: initQueryFactory

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
@Override
protected QueryExecutionFactory initQueryFactory() {

    // When we load the referenced schemata we do rdfs reasoning to avoid false errors
    // Many ontologies skip some domain / range statements and this way we add them
    OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF, ModelFactory.createDefaultModel());
    try {

        // load the data only when the model is empty in case it is initialized with the "copy constructor"
        // This sppeds up the process on very big in-memory datasets
        if (dumpModel.isEmpty()) {
            // load the data only when the model is empty in case it is initialized with the "copy constructor"
            dumpReader.read(dumpModel);
        }

        //if (dumpModel.isEmpty()) {
        //    throw new IllegalArgumentException("Dump is empty");
        //}
        //Load all the related ontologies as well (for more consistent querying
        for (SchemaSource src : getReferencesSchemata()) {
            ontModel.add(src.getModel());
        }
        // Here we add the ontologies in the dump mode
        // Note that the ontologies have reasoning enabled but not the dump source
        dumpModel.add(ontModel);
    } catch (Exception e) {
        log.error("Cannot read dump URI: " + getUri() + " Reason: " + e.getMessage());
        throw new IllegalArgumentException("Cannot read dump URI: " + getUri() + " Reason: " + e.getMessage(), e);
    }
    return masqueradeQEF(new QueryExecutionFactoryModel(dumpModel), this);
}
 
开发者ID:AKSW,项目名称:RDFUnit,代码行数:32,代码来源:DumpTestSource.java

示例8: initQueryFactory

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
@Override
protected QueryExecutionFactory initQueryFactory() {

    // When we load the referenced schemata we do rdfs reasoning to avoid false errors
    // Many ontologies skip some domain / range statements and this way we add them
    OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF, ModelFactory.createDefaultModel());
    try {

        // load the data only when the model is empty in case it is initialized with the "copy constructor"
        // This sppeds up the process on very big in-memory datasets
        if (dumpDataset.getDefaultModel().isEmpty() && !dumpDataset.listNames().hasNext() ) {
            // load the data only when the model is empty in case it is initialized with the "copy constructor"
            dumpReader.readDataset(dumpDataset);
        }

        //if (dumpModel.isEmpty()) {
        //    throw new IllegalArgumentException("Dump is empty");
        //}
        //Load all the related ontologies as well (for more consistent querying
        for (SchemaSource src : getReferencesSchemata()) {
            ontModel.add(src.getModel());
        }
        // Here we add the ontologies in the dump mode
        // Note that the ontologies have reasoning enabled but not the dump source
        dumpDataset.setDefaultModel(ontModel.union(dumpDataset.getDefaultModel()));
    } catch (Exception e) {
        log.error("Cannot read dump URI: " + getUri() + " Reason: " + e.getMessage());
        throw new IllegalArgumentException("Cannot read dump URI: " + getUri() + " Reason: " + e.getMessage(), e);
    }
    return masqueradeQEF(new QueryExecutionFactoryDataset(dumpDataset), this);
}
 
开发者ID:AKSW,项目名称:RDFUnit,代码行数:32,代码来源:DatasetTestSource.java

示例9: computeMappings

import org.apache.jena.ontology.OntModel; //导入方法依赖的package包/类
public List<? extends EvaluatedDescription<?>> computeMappings(SortedSet<OWLIndividual> positiveExamples, boolean useRemoteKB) 
            throws NonExistingLinksException, ComponentInitException {
        logger.info("positiveExamples: " + positiveExamples);
        //if there are no links to the target KB, then we can skip learning
        if (positiveExamples.isEmpty()) {
            throw new NonExistingLinksException();
        } else {
            //compute a mapping
            //get a sample of the positive examples
            SortedSet<OWLIndividual> positiveExamplesSample = SetManipulation.stableShrinkInd(positiveExamples, maxNrOfPositiveExamples);

            //starting from the positive examples, we first extract the fragment for them
            logger.info("Extracting fragment for positive examples...");
            mon.start();
            Model positiveFragment = targetKB.getFragment(positiveExamplesSample, MAX_RECURSION_DEPTH);
            mon.stop();
            logger.info("...got " + positiveFragment.size() + " triples in " + mon.getLastValue() + "ms.");
            //			for (OWLIndividual ind : positiveExamplesSample) {
            //				System.out.println(ResultSetFormatter.asText(
            //						org.apache.jena.query.QueryExecutionFactory.create("SELECT * WHERE {<" + ind.getName() + "> a ?o.}", positiveFragment).execSelect()));
            //			}

            //compute the negative examples
            logger.info("Computing negative examples...");
            MonitorFactory.getTimeMonitor("negative examples").start();

            AutomaticNegativeExampleFinderSPARQL2 negativeExampleFinder;
            //			if(useRemoteKB){
            negativeExampleFinder = new AutomaticNegativeExampleFinderSPARQL2(targetKB.getReasoner());
            //			}else{
            //				negativeExampleFinder = new AutomaticNegativeExampleFinderSPARQL2(targetKB.getReasoner(), targetKB.getNamespace());
            //			}
//            SortedSet<OWLIndividual> negativeExamples = negativeExampleFinder.getNegativeExamples(positiveExamples, maxNrOfNegativeExamples);
            SortedSet<OWLIndividual> negativeExamples = new TreeSet<>();
            negativeExamples.removeAll(positiveExamples);
            MonitorFactory.getTimeMonitor("negative examples").stop();
            logger.info("Found " + negativeExamples.size() + " negative examples in " + MonitorFactory.getTimeMonitor("negative examples").getTotal() + "ms.");
            logger.debug("Negative examples: " + negativeExamples);
            resultRecorder.setNegativeExample(negativeExamples, iterationNr, currentClass);

            //get a sample of the negative examples
            SortedSet<OWLIndividual> negativeExamplesSample = SetManipulation.stableShrinkInd(negativeExamples, maxNrOfNegativeExamples);

            //store negativeExamples 
            Map<OWLClass, SortedSet<OWLIndividual>> sourceClass2NegativeExample = new HashMap<OWLClass, SortedSet<OWLIndividual>>();
            sourceClass2NegativeExample.put(currentClass, negativeExamplesSample);

            //create fragment for negative examples
            logger.info("Extracting fragment for negative examples...");
            mon.start();
            Model negativeFragment;

            negativeFragment = targetKB.getFragment(negativeExamplesSample, MAX_RECURSION_DEPTH);

            mon.stop();
            logger.info("...got " + negativeFragment.size() + " triples in " + mon.getLastValue() + "ms.");

            logger.info("Learning input:");
            logger.info("Positive examples: " + positiveExamplesSample.size() + " with " + positiveFragment.size() + " triples, e.g. \n" + print(positiveExamplesSample, 3));
            logger.info("Negative examples: " + negativeExamplesSample.size() + " with " + negativeFragment.size() + " triples, e.g. \n" + print(negativeExamplesSample, 3));

            //create fragment consisting of both
            OntModel fullFragment = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
            fullFragment.add(positiveFragment);
            fullFragment.add(negativeFragment);
            fullFragment.add(targetKB.executeConstruct("CONSTRUCT {?s <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?o.} WHERE {?s <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?o.}"));
            filter(fullFragment, targetKB.getNamespace());

            //learn the class expressions
            return learnClassExpressions(fullFragment, positiveExamplesSample, negativeExamplesSample);
        }
    }
 
开发者ID:dice-group,项目名称:LASSIE,代码行数:73,代码来源:LASSIEController.java


注:本文中的org.apache.jena.ontology.OntModel.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。