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


Java Ontology类代码示例

本文整理汇总了Java中org.apache.jena.ontology.Ontology的典型用法代码示例。如果您正苦于以下问题:Java Ontology类的具体用法?Java Ontology怎么用?Java Ontology使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: initialize

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
@Override
public void initialize(final UimaContext context) throws ResourceInitializationException {
	super.initialize(context);

	model = ModelFactory.createOntologyModel();
	InputStream in = null;
	try {
		in = new FileInputStream(outputFileName);
		model.read(in, "http://github.com/quadrama/metadata/ontology.owl");
		in.close();
	} catch (IOException e) {
		Ontology o = model.createOntology("http://github.com/quadrama/metadata/ontology.owl");
		o.setRDFType(OWL2.Ontology);
		model.setNsPrefix("gndo", "http://d-nb.info/standards/elementset/gnd#");
		model.setNsPrefix("gnd", "http://d-nb.info/gnd/");
		model.setNsPrefix("dc", "http://purl.org/dc/elements/1.1/");
		model.setNsPrefix("oa", "http://www.w3.org/ns/oa#");
		model.setNsPrefix("dbo", "http://dbpedia.org/ontology/");
		model.setNsPrefix("qd", QD.NS);
	} finally {
		IOUtils.closeQuietly(in);
	}

}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:25,代码来源:MetaDataExport.java

示例2: Skolemizer

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
public Skolemizer(Ontology ontology, UriBuilder baseUriBuilder, UriBuilder absolutePathBuilder)
   {
if (ontology == null) throw new IllegalArgumentException("Ontology cannot be null");
if (baseUriBuilder == null) throw new IllegalArgumentException("UriBuilder cannot be null");
if (absolutePathBuilder == null) throw new IllegalArgumentException("UriBuilder cannot be null");
       this.ontology = ontology;        
       this.baseUriBuilder = baseUriBuilder;
       this.absolutePathBuilder = absolutePathBuilder;    
   }
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:10,代码来源:Skolemizer.java

示例3: Item

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
public Item(@Context UriInfo uriInfo, @Context Request request, @Context MediaTypes mediaTypes,
           @Context SPARQLEndpoint sparqlEndpoint, @Context GraphStore graphStore,
           @Context com.atomgraph.processor.model.Application application, @Context Ontology ontology, @Context TemplateCall templateCall,
           @Context HttpHeaders httpHeaders, @Context ResourceContext resourceContext)
   {
super(uriInfo, request, mediaTypes,
               sparqlEndpoint, graphStore,
               application, ontology, templateCall,
               httpHeaders, resourceContext);
if (log.isDebugEnabled()) log.debug("Constructing {} as direct indication of GRAPH {}", getClass(), uriInfo.getAbsolutePath());
   }
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:12,代码来源:Item.java

示例4: OntologyProvider

import org.apache.jena.ontology.Ontology; //导入依赖的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

示例5: check

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
public void check(Ontology ontology)
{
    if (ontology == null) throw new IllegalArgumentException("Ontology cannot be null");
    
    marked.put(ontology, Boolean.TRUE);
    onStack.put(ontology, Boolean.TRUE);

    ExtendedIterator<OntResource> it = ontology.listImports();
    try
    {
        while (it.hasNext())
        {
            OntResource importRes = it.next();
            if (importRes.canAs(Ontology.class))
            {
                Ontology imported = importRes.asOntology();
                if (marked.get(imported) == null)
                    check(imported);
                else if (onStack.get(imported))
                {
                    cycleOntology = imported;
                    return;
                }
            }
        }

        onStack.put(ontology, Boolean.FALSE);
    }
    finally
    {
        it.close();
    }
}
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:34,代码来源:OntologyProvider.java

示例6: getInjectable

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
@Override
   public Injectable<Ontology> getInjectable(ComponentContext cc, Context context)
   {	
return new Injectable<Ontology>()
{
    @Override
    public Ontology getValue()
    {
               return getOntology();
    }
};
   }
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:13,代码来源:OntologyProvider.java

示例7: getOntology

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
public Ontology getOntology()
{
    OntModelSpec ontModelSpec = OntModelSpec.OWL_MEM;
    
    // attempt to use DataManager to retrieve owl:import Models
    if (getOntDocumentManager().getFileManager() instanceof DataManager)
        ontModelSpec.setImportModelGetter((DataManager)getOntDocumentManager().getFileManager());
    
    return getOntModel(getOntDocumentManager(), getOntologyURI(), ontModelSpec).getOntology(getOntologyURI());
}
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:11,代码来源:OntologyProvider.java

示例8: skolemize

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
public Model skolemize(Ontology ontology, UriBuilder baseUriBuilder, UriBuilder absolutePathBuilder, Model model)
{
    try
    {
        return new Skolemizer(ontology, baseUriBuilder, absolutePathBuilder).build(model);
    }
    catch (IllegalArgumentException ex)
    {
        throw new SkolemizationException(ex, model);
    }
}
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:12,代码来源:SkolemizingModelProvider.java

示例9: post

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
@Override
public RESTResource post(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
	
	String data = "";
	String ontologyUri = null;
	try {
		data = ThingDescriptionUtils.streamToString(payload);
		ontologyUri = new URI(data).toString();
		data = null;
	} catch (IOException e1) {
		e1.printStackTrace();
		throw new BadRequestException();
	} catch (URISyntaxException e2) {
		// do nothing
	}
	
	Dataset dataset = ThingDirectory.get().dataset;
	dataset.begin(ReadWrite.WRITE);
	try {
		String rootId = null;
		
		OntModel ontology = ModelFactory.createOntologyModel();
		if (data == null) {
			ontology.read(ontologyUri.toString(), "Turtle");
		} else {
			ontologyUri = "http://example.org/"; // TODO
			ontology.read(new ByteArrayInputStream(data.getBytes("UTF-8")), ontologyUri, "Turtle");
		}

		Model tdb = dataset.getDefaultModel();
		
		ExtendedIterator<Ontology> it = ontology.listOntologies();
		if (!it.hasNext()) {
				throw new BadRequestException();
		}
		while (it.hasNext()) {
			Ontology o = it.next();
			
			String prefix = ontology.getNsURIPrefix(o.getURI());
			// if no prefix found, generates id
			String id = (prefix != null && !prefix.isEmpty()) ? prefix : generateID();
			URI resourceUri = URI.create(normalize(uri) + "/" + id);
			
			OntModel axioms;
			if (isRootOntology(o.getURI(), ontology)) {
				rootId = id;
				axioms = ontology;
			} else {
				axioms = ontology.getImportedModel(o.getURI());
			}
			
			// TODO Check if the vocab isn't already registered in the dataset
			dataset.addNamedModel(resourceUri.toString(), axioms);
			
			Date currentDate = new Date(System.currentTimeMillis());
			DateFormat f = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
			tdb.getResource(resourceUri.toString()).addProperty(DCTerms.source, ontologyUri);
			tdb.getResource(resourceUri.toString()).addProperty(DCTerms.created, f.format(currentDate));

			addToAll("/vocab/" + id, new VocabularyHandler(id, instances));

			ThingDirectory.LOG.info(String.format("Registered RDFS/OWL vocabulary %s (id: %s)", o.getURI(), id));
		}
		
		dataset.commit();
		
		RESTResource resource = new RESTResource("/vocab/" + rootId, new VocabularyHandler(rootId, instances));
		return resource;

	} catch (Exception e) {
		e.printStackTrace();
		throw new RESTException();
	} finally {
		dataset.end();
	}
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:77,代码来源:VocabularyCollectionHandler.java

示例10: TemplateMatcher

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
public TemplateMatcher(Ontology ontology)
{
    this.ontology = ontology;
}
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:5,代码来源:TemplateMatcher.java

示例11: match

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
/**
 * Matches path (relative URI) against URI templates in sitemap ontology.
 * This method uses Jersey implementation of the JAX-RS URI matching algorithm.
 * 
 * @param ontology sitemap ontology
 * @param path URI path
 * @param level
 * @return URI template/class mapping
 */    
public List<TemplatePrecedence> match(Ontology ontology, CharSequence path, int level)
{
    if (ontology == null) throw new IllegalArgumentException("Ontology cannot be null");
    if (path == null) throw new IllegalArgumentException("CharSequence cannot be null");
    
    if (log.isTraceEnabled()) log.trace("Matching path '{}' against resource templates in sitemap: {}", path, ontology);
    if (log.isTraceEnabled()) log.trace("Ontology import level: {}", level);
    List<TemplatePrecedence> matches = new ArrayList<>();

    ResIterator it = ontology.getOntModel().listResourcesWithProperty(RDF.type, LDT.Template);
    try
    {
        while (it.hasNext())
        {
            Template template = it.next().as(Template.class);
            // only match templates defined in this ontology - maybe reverse loops?
            if (template.getIsDefinedBy() != null && template.getIsDefinedBy().equals(ontology))
            {
                if (template.getPath() == null)
                {
                    if (log.isErrorEnabled()) log.error("Template class {} does not have value for {} annotation", template, LDT.path);
                    throw new OntologyException("Template class '" + template + "' does not have value for '" + LDT.path + "' annotation");
                }

                UriTemplate uriTemplate = template.getPath();
                HashMap<String, String> map = new HashMap<>();

                if (uriTemplate.match(path, map))
                {
                    if (log.isTraceEnabled()) log.trace("Path {} matched UriTemplate {}", path, uriTemplate);
                    if (log.isTraceEnabled()) log.trace("Path {} matched OntClass {}", path, template);
                    
                    TemplatePrecedence precedence = new TemplatePrecedence(template, level * -1);
                    matches.add(precedence);
                }
                else
                    if (log.isTraceEnabled()) log.trace("Path {} did not match UriTemplate {}", path, uriTemplate);
            }
        }

        List<Ontology> importedOntologies = new ArrayList<>(); // collect imports first to avoid CME within iterator
        ExtendedIterator<OntResource> importIt = ontology.listImports();
        try
        {
            while (importIt.hasNext())
            {
                OntResource importRes = importIt.next();
                if (importRes.canAs(Ontology.class)) importedOntologies.add(importRes.asOntology());
            }
        }
        finally
        {
            importIt.close();
        }
        
        //traverse imports recursively, safely make changes to OntModel outside the iterator
        for (Ontology importedOntology : importedOntologies)
            matches.addAll(match(importedOntology, path, level + 1));            
    }
    finally
    {
        it.close();
    }

    return matches;
}
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:76,代码来源:TemplateMatcher.java

示例12: getOntology

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
public Ontology getOntology()
{
    return ontology;
}
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:5,代码来源:TemplateMatcher.java

示例13: match

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
public SortedSet<ClassPrecedence> match(Ontology ontology, Resource resource, Property property, int level)
   {
       if (ontology == null) throw new IllegalArgumentException("Ontology cannot be null");
if (resource == null) throw new IllegalArgumentException("Resource cannot be null");
if (property == null) throw new IllegalArgumentException("Property cannot be null");

       SortedSet<ClassPrecedence> matchedClasses = new TreeSet<>();
       ResIterator it = ontology.getOntModel().listResourcesWithProperty(LDT.segment);
       try
       {
           while (it.hasNext())
           {
               Resource ontClassRes = it.next();
               OntClass ontClass = ontology.getOntModel().getOntResource(ontClassRes).asClass();
               // only match templates defined in this ontology - maybe reverse loops?
               if (ontClass.getIsDefinedBy() != null && ontClass.getIsDefinedBy().equals(ontology) &&
                       resource.hasProperty(property, ontClass))
               {
                   ClassPrecedence template = new ClassPrecedence(ontClass, level * -1);
                   if (log.isTraceEnabled()) log.trace("Resource {} matched OntClass {}", resource, ontClass);
                   matchedClasses.add(template);
               } 
           }            
       }
       finally
       {
           it.close();
       }

       ExtendedIterator<OntResource> imports = ontology.listImports();
       try
       {
           while (imports.hasNext())
           {
               OntResource importRes = imports.next();
               if (importRes.canAs(Ontology.class))
               {
                   Ontology importedOntology = importRes.asOntology();
                   // traverse imports recursively
                   Set<ClassPrecedence> matchedImportClasses = match(importedOntology, resource, property, level + 1);
                   matchedClasses.addAll(matchedImportClasses);
               }
           }
       }
       finally
       {
           imports.close();
       }
       
       return matchedClasses;
   }
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:52,代码来源:Skolemizer.java

示例14: getCycleOntology

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
public Ontology getCycleOntology()
{
    return cycleOntology;
}
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:5,代码来源:OntologyProvider.java

示例15: getContext

import org.apache.jena.ontology.Ontology; //导入依赖的package包/类
@Override
public Ontology getContext(Class<?> type)
{
    return getOntology();
}
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:6,代码来源:OntologyProvider.java


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