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


Java OntClass.isAnon方法代码示例

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


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

示例1: findAllLabels

import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public LinkedList<SemanticConcept> findAllLabels(String ontologyUri,String rootClass){
    
    LinkedList<SemanticConcept> list = new LinkedList<>();
    
    try{
    
        //Create a reasoner
        OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);

        //Create new URL of ontology
        URL url = new URL(ontologyUri);
    
        //Create model for the ontology
        model.read(url.openStream(),null);
    
        //Load model to the reasoner
        model.prepare();
    
        //Compute the classification tree
        ((PelletInfGraph) model.getGraph()).getKB().classify();
        
        //Set OWL root element (e.g., it could be thing: model.getOntClass(OWL.Thing.getURI()))
        OntClass owlRoot = model.getOntClass(rootClass);
        
        SemanticConcept sc = new SemanticConcept();
        sc.setUrl(owlRoot.getURI());
        sc.setName("");
        sc.setSemanticSimilarity("");
        list.add(sc);
    
        //For each subclass (direct or indirect)
        for (Iterator it = owlRoot.listSubClasses(false); it.hasNext();) {

            OntClass subclass = (OntClass) it.next();

            //If subclass is not anonymous
            if (!subclass.isAnon()) {

                //If subclass is not nothing
                if(!subclass.getURI().equals(com.hp.hpl.jena.vocabulary.OWL.Nothing.getURI())){
                    
                    sc = new SemanticConcept();
                    sc.setUrl(subclass.getURI());
                    sc.setName("");
                    sc.setSemanticSimilarity("");
                
                    list.add(sc);
                }
            }
        }
        
    }catch(IOException ex){}
    
    return list;
    
}
 
开发者ID:usplssb,项目名称:SemanticSCo,代码行数:57,代码来源:SemanticReasoner.java

示例2: getXSDTypeFromRangeExpensiveMethod

import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private String getXSDTypeFromRangeExpensiveMethod(OntResource range) {
    ExtendedIterator<OntClass> iter = range.asClass().listSuperClasses();
    while (iter.hasNext()) {
        OntClass superc = iter.next();
        if (!superc.isAnon()) {
            String type = getXSDTypeFromRange(superc);
            if (type != null)
                return type;
        }
    }
    return null;
}
 
开发者ID:BenzclyZhang,项目名称:BimSPARQL,代码行数:13,代码来源:RDFWriter.java

示例3: ontClassInThisModel

import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private OntClass ontClassInThisModel(OntClass cls) {
	// make sure we have the class in this model
	if (cls != null) {
		if (!cls.isAnon()) {
			cls = getJenaModel().createClass(cls.getURI());
		}
		else {
			OntResource newor = getJenaModel().getOntResource(cls);
			if (newor.canAs(OntClass.class)) {
				cls = newor.as(OntClass.class);
			}
		}
	}
	return cls;
}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:16,代码来源:ModelManager.java

示例4: createTree

import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private Node createTree(OntClass owlClass) {
    
    //If is a class Nothing, return null
    if(owlClass.getURI().equals(com.hp.hpl.jena.vocabulary.OWL.Nothing.getURI()))
        return null;

    //Create new node, and set name and url
    Node node = new Node();
    node.setName(owlClass.getLabel(null));
    node.setUrl(owlClass.getURI());
    
    //Create list of processed subclasses
    HashMap<String,String> processedSubclasses = new HashMap<>();
    
    //For each direct subclass
    for(Iterator it=owlClass.listSubClasses(true);it.hasNext();){
        
        OntClass subclass = (OntClass) it.next();
        
        //If subclass is not anonymous
        if(!subclass.isAnon()){
            
            //If subclass was not already processed
            if(!processedSubclasses.containsKey(subclass.getURI())){
                
                //Recursively call method "createTree" to process subclass
                Node subNode = createTree(subclass);
                
                //If subclass is not owl:Nothing, create add subclass to parent node. Otherwise, the returned node is null
                if(subNode != null) {
                    
                    //Add subclass node to parent node
                    node.getChildrenNode().add(subNode);
                    
                    //Add subclass to list of processed subclasses
                    processedSubclasses.put(subNode.getUrl(),subNode.getName());
        
                }
            }
        }
    }
    
    return node;   
    
}
 
开发者ID:usplssb,项目名称:SemanticSCo,代码行数:46,代码来源:SemanticReasoner.java

示例5: ontClassToString

import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private String ontClassToString(OntClass cls, OntClass subclass) {
		if (cls.isUnionClass()) {
			return getUnionClassRangeString(cls.asUnionClass());
		}
		else if (cls.isIntersectionClass()) {
			return getIntersectionClassRangeString(cls.asIntersectionClass());
		}
		else if (cls.isRestriction()) {
			if (!shouldResourceBeOutput(cls, true, false, false)) {
				Restriction rest = cls.asRestriction();
				Property onProp = rest.getOnProperty();
				if (rest.isAllValuesFromRestriction()) {
					Resource avfr = rest.asAllValuesFromRestriction().getAllValuesFrom();
					addRestriction(subclass, resourceToString(onProp, false) + " of " + resourceToString(subclass, false) + " only has values of type " + 
							resourceToString(avfr, false) + ".\n");
				}
				else if (rest.isSomeValuesFromRestriction()) {
					Resource svfr = rest.asSomeValuesFromRestriction().getSomeValuesFrom();
					addRestriction(subclass, resourceToString(onProp, false) + " of " + resourceToString(subclass, false) + " has at least one value of type " + 
							resourceToString(svfr, false) + ".\n");				
				}
				else if (rest.isMaxCardinalityRestriction()) {
					int maxCard = rest.asMaxCardinalityRestriction().getMaxCardinality();
					addRestriction(subclass, resourceToString(onProp, false) + " of " + resourceToString(subclass, false) + " has at most " + 
							maxCard + (maxCard > 1 ? " values.\n" : " value.\n"));
				}
				else if (rest.isMinCardinalityRestriction()) {
					int minCard = rest.asMinCardinalityRestriction().getMinCardinality();
					addRestriction(subclass, resourceToString(onProp, false) + " of " + resourceToString(subclass, false) + " has at least " + 
							minCard + (minCard > 1 ? " values.\n" : " value.\n"));
				}
				else if (rest.isCardinalityRestriction()) {
					int card = rest.asCardinalityRestriction().getCardinality();
					addRestriction(subclass, resourceToString(onProp, false) + " of " + resourceToString(subclass, false) + " has exactly " + 
							card + (card > 1 ? " values.\n" : " value.\n"));
				}
				else if (rest.isHasValueRestriction()) {
					RDFNode hvr = rest.asHasValueRestriction().getHasValue();
					addRestriction(subclass, resourceToString(onProp, false) + " of " + resourceToString(subclass, false) + " always has value " + 
							rdfNodeToString(hvr, 0) + " .\n");				
				}
				else {
					System.out.println("Unhandled restriction: " + rest.getClass());
				}
				resourcesOutput.add(cls);
			}
			if (cls.isAnon()) {
//				System.out.println("returning null on anon restriction--should this happen??");
				return null;
			}
			else {
				return cls.toString();
			}
			
		}
		else if (cls.isEnumeratedClass()) {
			EnumeratedClass enumcls = cls.asEnumeratedClass();
			return enumeratedClassToString(enumcls);
		}
		else if (cls.isComplementClass()) {
			ComplementClass ccls = cls.asComplementClass();
			OntClass thecls = ccls.getDisjointWith();
			if (thecls != null) {
				return resourceToString(thecls, false);
			}
			else {
				return null;
			}
		}
		else if (!cls.isAnon()) {
			return resourceToString(cls, false);
		}
		else {
			System.out.println("Anon class; returning string equivalent--this shouldn't happen.");
			return cls.toString();
		}
	}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:78,代码来源:OwlToSadl.java


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