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


Java OntClass.canAs方法代码示例

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


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

示例1: renderHierarchy

import org.apache.jena.ontology.OntClass; //导入方法依赖的package包/类
protected static void renderHierarchy(PrintStream out, OntClass cls, List<Object> occurs, int depth) {
  renderClassDescription(out, cls, depth);
  out.println();

  // recurse to the next level down
  if (cls.canAs(OntClass.class) && !occurs.contains(cls)) {
    for (Iterator<?> i = cls.listSubClasses(true); i.hasNext(); ) {
      OntClass sub = (OntClass) i.next();

      // we push this expression on the occurs list before we recurse
      occurs.add(cls);
      renderHierarchy(out, sub, occurs, depth + 1);
      occurs.remove(cls);
    }
    for (Iterator<?> i = cls.listInstances(); i.hasNext(); ) {
      Individual individual = (Individual) i.next();
      renderURI(out, individual.getModel(), individual.getURI());
      out.print(" [");
      for (Iterator<?> j = individual.listLabels(null); j.hasNext(); ) {
        out.print(((Literal) j.next()).getString() + ", ");
      }
      out.print("] ");
      out.println();
    }
  }
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:27,代码来源:LocalOntology.java

示例2: hasSuperTemplate

import org.apache.jena.ontology.OntClass; //导入方法依赖的package包/类
@Override
   public final boolean hasSuperTemplate(Template superTemplate)
   {
if (superTemplate == null) throw new IllegalArgumentException("Template cannot be null");
       
       ExtendedIterator<OntClass> it = listSuperClasses(false);
       try
       {
           while (it.hasNext())
           {
               OntClass nextClass = it.next();
               if (nextClass.canAs(Template.class))
               {
                   Template nextTemplate = nextClass.as(Template.class);
                   if (nextTemplate.equals(superTemplate) || nextTemplate.hasSuperTemplate(superTemplate))
                       return true;
               }
           }
       }
       finally
       {
           it.close();
       }
       
       return false;
   }
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:27,代码来源:TemplateImpl.java

示例3: addSuperParameters

import org.apache.jena.ontology.OntClass; //导入方法依赖的package包/类
protected Map<Property, Parameter> addSuperParameters(Template template, Map<Property, Parameter> args)
{
    if (template == null) throw new IllegalArgumentException("Template Set cannot be null");        
    if (args == null) throw new IllegalArgumentException("Parameter Map cannot be null");        
    
    ExtendedIterator<OntClass> superIt = template.listSuperClasses();
    try
    {
        while (superIt.hasNext())
        {
            OntClass superClass = superIt.next();
            if (superClass.canAs(Template.class))
            {
                Template superTemplate = superClass.as(Template.class);
                Map<Property, Parameter> superArgs = superTemplate.getLocalParameters();
                Iterator<Entry<Property, Parameter>> entryIt = superArgs.entrySet().iterator();
                while (entryIt.hasNext())
                {
                    Entry<Property, Parameter> entry = entryIt.next();
                    args.putIfAbsent(entry.getKey(), entry.getValue()); // reject Parameters for existing predicates
                }
                
                addSuperParameters(superTemplate, args);  // recursion to super class
            }
        }
    }
    finally
    {
        superIt.close();
    }

    return args;
}
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:34,代码来源:TemplateImpl.java

示例4: getAbsolutePathBuilder

import org.apache.jena.ontology.OntClass; //导入方法依赖的package包/类
public UriBuilder getAbsolutePathBuilder(OntClass ontClass)
{
    if (ontClass == null) throw new IllegalArgumentException("OntClass cannot be null");

    ExtendedIterator<OntClass> superClassIt = ontClass.listSuperClasses();
    try
    {
        while (superClassIt.hasNext())
        {
            OntClass superClass = superClassIt.next();
            if (superClass.canAs(HasValueRestriction.class))
            {
                HasValueRestriction hvr = superClass.as(HasValueRestriction.class);
                if (hvr.getOnProperty().equals(SIOC.HAS_PARENT) || hvr.getOnProperty().equals(SIOC.HAS_CONTAINER))
                {
                    if (!hvr.getHasValue().isURIResource())
                    {
                        if (log.isErrorEnabled()) log.error("Value restriction on class {} for property {} is not a URI resource", ontClass, hvr.getOnProperty());
                        throw new OntologyException("Value restriction on class '" + ontClass + "' for property '" + hvr.getOnProperty() + "' is not a URI resource");
                    }
                    
                    Resource absolutePath = hvr.getHasValue().asResource();
                    return UriBuilder.fromUri(absolutePath.getURI());
                }
            }
        }
    }
    finally
    {
        superClassIt.close();
    }

    return getAbsolutePathBuilder();
}
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:35,代码来源:Skolemizer.java

示例5: addInstance

import org.apache.jena.ontology.OntClass; //导入方法依赖的package包/类
public Resource addInstance(OntClass forClass, Property property, Resource instance, String baseURI, Set<OntClass> reachedClasses)
{
    if (forClass == null) throw new IllegalArgumentException("OntClass cannot be null");
    if (property == null) throw new IllegalArgumentException("Property cannot be null");
    if (instance == null) throw new IllegalArgumentException("Resource cannot be null");
    if (baseURI == null) throw new IllegalArgumentException("Base URI string cannot be null");
    if (reachedClasses == null) throw new IllegalArgumentException("Set<OntClass> cannot be null");

    constructInstance(forClass, property, instance, baseURI, new HashSet<OntClass>()).
            addProperty(RDF.type, forClass);
    reachedClasses.add(forClass);

    // evaluate AllValuesFromRestriction to construct related instances
    ExtendedIterator<OntClass> superClassIt = forClass.listSuperClasses();
    try
    {
        while (superClassIt.hasNext())
        {
            OntClass superClass = superClassIt.next();

            // construct restriction
            if (superClass.canAs(AllValuesFromRestriction.class))
            {
                AllValuesFromRestriction avfr = superClass.as(AllValuesFromRestriction.class);
                if (avfr.getAllValuesFrom().canAs(OntClass.class))
                {
                    OntClass valueClass = avfr.getAllValuesFrom().as(OntClass.class);
                    if (reachedClasses.contains(valueClass))
                    {
                        if (log.isErrorEnabled()) log.error("Circular template restriction between '{}' and '{}' is not allowed", forClass.getURI(), valueClass.getURI());
                        throw new OntologyException("Circular template restriction between '" + forClass.getURI() + "' and '" + valueClass.getURI() + "' is not allowed");
                    }

                    Resource value = instance.getModel().createResource().
                            addProperty(RDF.type, valueClass);
                    instance.addProperty(avfr.getOnProperty(), value);

                    // add inverse properties
                    ExtendedIterator<? extends OntProperty> it = avfr.getOnProperty().listInverseOf();
                    try
                    {
                        while (it.hasNext())
                        {
                            value.addProperty(it.next(), instance);
                        }
                    }
                    finally
                    {
                        it.close();
                    }

                    addInstance(valueClass, property, value, baseURI, reachedClasses);
                }
            }
        }
    }
    finally
    {
        superClassIt.close();
    }

    return instance;
}
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:64,代码来源:Constructor.java


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