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


Java RDFNode.asResource方法代码示例

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


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

示例1: initializeCategories

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public Set<String> initializeCategories() {
	Model model = ModelFactory.createDefaultModel();
	model.read("/home/zwicklbauer/HDTGeneration/skos_categories_en.nt");
	StmtIterator it = model.listStatements();
	Set<String> set = new HashSet<String>();
	
	System.out.println("Los gehts");
	while (it.hasNext()) {
		Statement s = it.next();
		Resource r = s.getSubject();
		Property p = s.getPredicate();
		RDFNode n = s.getObject();
		if (p.getURI().equalsIgnoreCase(
				"http://www.w3.org/2004/02/skos/core#broader")
				&& n.isResource()) {
			Resource target = n.asResource();
			if(!hasSubCategory(target.getURI())) 
			set.add(target.getURI());
			if(!hasSubCategory(r.getURI())) 
			set.add(r.getURI());
		}
	}
	return set;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:25,代码来源:DbpediaGraphModification.java

示例2: testRule

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
@Test
public void testRule() throws Exception {
  Node var = NodeFactory.createAnon();
  
  System.out.println("Node: " + var);
  
  KBCollection varCol = new KBCollectionImpl("http://www.w3.org/2007/rif#var");
  RDFNode varRdf = KBObjectImpl.getBaseContextModel().asRDFNode(var);
  System.out.println("RDF Node: " + varRdf);

  Resource varRes = varRdf.asResource();
  System.out.println("Resource: " + varRes.getLocalName() + ", " + varRes.getNameSpace() + ", " + varRes.getURI());
  // Individual varInd = ((KBCollectionImpl)varCol).getCore().createIndividual();//.createIndividual(varRes.getURI());
  // KBObjectImpl.getBaseContextModel().createIndividual(((KBCollectionImpl)varCol).getCore());
  
  Variable v = new VariableImpl("vijayvar");
  System.out.println("Var Name: " + v.getName());
  FileWriter fw = new FileWriter("/scratch/WORK2/jena/testModels/test4.xml");
  RDFDataMgr.write(fw, KBObjectImpl.getDataset(), RDFFormat.NQUADS);
  
}
 
开发者ID:vijayrajak,项目名称:JenaKBClient,代码行数:22,代码来源:KBIndividualImplTest.java

示例3: addSkosBroaderToGraph

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private void addSkosBroaderToGraph() {
	Model m = ModelFactory.createDefaultModel();
	m.read(SKOSBROADER);
	StmtIterator it = m.listStatements();
	while (it.hasNext()) {
		Statement s = it.next();
		Resource subject = s.getSubject();
		Property pra = s.getPredicate();
		RDFNode object = s.getObject();
		if (object.isResource()) {
			Resource obj = object.asResource();
			if (pra.isResource()
					&& obj.getURI().startsWith(
							"http://dbpedia.org/resource/")) {
				if (!subject.getURI().equalsIgnoreCase(obj.getURI())) {
					graph.addVertex(subject.getURI());
					graph.addVertex(obj.getURI());
					graph.addEdge(subject.getURI(), obj.getURI());
				}
			}
		}
	}
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:24,代码来源:CreateRandomDBpediaModel.java

示例4: sportsTeamsSurfaceForms

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public void sportsTeamsSurfaceForms() {
	Model m = ModelFactory.createDefaultModel();

	m.read(INSTANCEMAPPINGTYPES_NT);

	StmtIterator it = m.listStatements();

	while (it.hasNext()) {
		Statement s = it.next();
		Resource subject = s.getSubject();
		RDFNode object = s.getObject();

		if (object.isResource()) {
			Resource obj = object.asResource();
			if (obj.getURI().equalsIgnoreCase("http://dbpedia.org/ontology/SportsTeam")) {
				teams.add(subject.getURI());
			}
		}
	}
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:21,代码来源:CreateDBpediaIndexV2.java

示例5: enrichImpl

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private void enrichImpl(StmtIterator iter, Collection<Resource> toRemove, CSVWriter printer)
{
    for ( Statement stmt : iter.toList())
    {
        RDFNode  node   = stmt.getObject();
        if ( !node.isResource() ) { continue; }

        Resource target = node.asResource();
        if ( !isEntity(target)  ) { continue; }

        String   label  = getLabel(target);
        if ( label == null      ) { continue; }

        printEnrichment(stmt, label, printer);

        stmt.changeObject(label);
        toRemove.add(target);
    }
}
 
开发者ID:hugomanguinhas,项目名称:europeana,代码行数:20,代码来源:DatasetProcessor.java

示例6: createGraph

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public UndirectedGraph<String, DefaultEdge> createGraph() {
	Model model = ModelFactory.createDefaultModel();
	model.read("/home/zwicklbauer/HDTGeneration/skos_categories_en.nt");
	StmtIterator it = model.listStatements();
	UndirectedGraph<String, DefaultEdge> graph = new MiGrafo();
	Set<String> set = new HashSet<String>();

	int counter = 0;
	while (it.hasNext()) {
		Statement s = it.next();
		Resource r = s.getSubject();
		Property p = s.getPredicate();
		RDFNode n = s.getObject();
		if (p.getURI().equalsIgnoreCase(
				"http://www.w3.org/2004/02/skos/core#broader")
				&& n.isResource()) {
			set.add(r.getURI());
			Resource target = n.asResource();
			set.add(target.getURI());
			if (!graph.containsVertex(r.getURI())) {
				graph.addVertex(r.getURI());
			}
			if (!graph.containsVertex(target.getURI())) {
				graph.addVertex(target.getURI());
			}
			graph.addEdge(r.getURI(), target.getURI());
			if (counter % 10000 == 0) {
				System.out.println(counter);
			}
			counter++;
		}
	}
	return graph;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:35,代码来源:Sampling.java

示例7: addCategoriesToGraph

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
private void addCategoriesToGraph() {
	Model m = ModelFactory.createDefaultModel();
	m.read(ARTICLECATEGORIES);
	StmtIterator it = m.listStatements();
	int counter = 0;
	while (it.hasNext()) {
		if (counter % 10000 == 0) {
			System.out.println(counter);
		}
		Statement s = it.next();
		Resource subject = s.getSubject();
		Property pra = s.getPredicate();
		RDFNode object = s.getObject();
		if (object.isResource()) {
			Resource obj = object.asResource();
			if (pra.isResource()
					&& obj.getURI().startsWith(
							"http://dbpedia.org/resource/")) {
				if (!subject.getURI().equalsIgnoreCase(obj.getURI())) {
					graph.addVertex(subject.getURI());
					graph.addVertex(obj.getURI());
					graph.addEdge(subject.getURI(), obj.getURI());
				}
			}
		}
	}
	counter++;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:29,代码来源:CreateRandomDBpediaModel.java

示例8: fillRelationsIndex

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public void fillRelationsIndex() {
	Model m = ModelFactory.createDefaultModel();

	m.read(MAPPINGPROPERTIES);

	StmtIterator it = m.listStatements();

	while (it.hasNext()) {
		Statement s = it.next();
		Resource subject = s.getSubject();
		Property pra = s.getPredicate();
		RDFNode object = s.getObject();
		if (object.isResource()) {
			Resource obj = object.asResource();
			if (pra.isResource()
					&& obj.getURI().startsWith(
							"http://dbpedia.org/resource/")) {
				if (!relationmap.containsKey(subject.getURI())) {
					LinkedList<String> list = new LinkedList<String>();
					relationmap.put(subject.getURI(), list);
				}
				LinkedList<String> l = relationmap.get(subject.getURI());
				l.add(pra.getURI().replaceAll(
						"http://dbpedia.org/ontology/", "dbpediaOnt/")
						+ ":::"
						+ obj.getURI().replaceAll(
								"http://dbpedia.org/resource/",
								"dbpediaRes/"));

			}
		}
	}
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:34,代码来源:CreateDBPediaIndex.java

示例9: fillPropertiesIndex

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public void fillPropertiesIndex() {
	Model m = ModelFactory.createDefaultModel();

	m.read(INFOBOXPROPERTIES);

	StmtIterator it = m.listStatements();

	while (it.hasNext()) {
		Statement s = it.next();
		Resource subject = s.getSubject();
		Property pra = s.getPredicate();
		RDFNode object = s.getObject();
		if (object.isResource()) {
			Resource obj = object.asResource();
			if (pra.isResource() && obj.getURI().startsWith("http://dbpedia.org/resource/")) {
				if (!relationmap.containsKey(subject.getURI())) {
					LinkedList<String> list = new LinkedList<String>();
					relationmap.put(subject.getURI(), list);
				}
				LinkedList<String> l = relationmap.get(subject.getURI());
				l.add(pra.getURI().replaceAll("http://dbpedia.org/property/", "dbpediaOnt/") + ":::"
						+ obj.getURI().replaceAll("http://dbpedia.org/resource/", "dbpediaRes/"));

			}
		}
	}
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:28,代码来源:CreateDBpediaIndexV2.java

示例10: fillRelationsIndex

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
public void fillRelationsIndex() {
	Model m = ModelFactory.createDefaultModel();

	m.read(MAPPINGPROPERTIES);

	StmtIterator it = m.listStatements();

	while (it.hasNext()) {
		Statement s = it.next();
		Resource subject = s.getSubject();
		Property pra = s.getPredicate();
		RDFNode object = s.getObject();
		if (object.isResource()) {
			Resource obj = object.asResource();
			if (pra.isResource() && obj.getURI().startsWith("http://dbpedia.org/resource/")) {
				if (!relationmap.containsKey(subject.getURI())) {
					LinkedList<String> list = new LinkedList<String>();
					relationmap.put(subject.getURI(), list);
				}
				LinkedList<String> l = relationmap.get(subject.getURI());
				l.add(pra.getURI().replaceAll("http://dbpedia.org/ontology/", "dbpediaOnt/") + ":::"
						+ obj.getURI().replaceAll("http://dbpedia.org/resource/", "dbpediaRes/"));

			}
		}
	}
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:28,代码来源:CreateDBpediaIndexV2.java

示例11: addHigherIncludedDolceClass

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
protected static void addHigherIncludedDolceClass(Set<Resource> classes, Model dolceClassModel,
        Set<Resource> unlinkedDolceClasses) {
    Queue<Resource> queue = new LinkedList<Resource>(classes);
    Resource classResource, superClass, subClass;
    RDFNode node;
    NodeIterator nodeIterator;
    ResIterator resIterator;
    boolean addClass;
    while (!queue.isEmpty()) {
        classResource = queue.poll();
        if (dolceClassModel.containsResource(classResource)) {
            nodeIterator = dolceClassModel.listObjectsOfProperty(classResource, RDFS.subClassOf);
            while (nodeIterator.hasNext()) {
                node = nodeIterator.next();
                if (node.isResource()) {
                    superClass = node.asResource();
                    // get all sub classes of this class
                    resIterator = dolceClassModel.listSubjectsWithProperty(RDFS.subClassOf, superClass);
                    addClass = true;
                    // Check that all sub classes of this super class are
                    // already in
                    // the list of classes or are marked as unlinked classes
                    while (resIterator.hasNext() && addClass) {
                        subClass = resIterator.next();
                        addClass = classes.contains(subClass) || unlinkedDolceClasses.contains(subClass);
                    }
                    if (addClass) {
                        classes.add(superClass);
                        queue.add(superClass);
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug("Added " + superClass.getURI());
                        }
                    }
                } else {
                    LOGGER.error("Expected a resource in the statement (" + classResource + ", rdfs:subClassOf, "
                            + node + "). Ignoring this statement.");
                }
            }
        }
    }
}
 
开发者ID:dice-group,项目名称:Cetus,代码行数:42,代码来源:YagoBasedTypeSearcher.java

示例12: searchDolceSuperClasses

import com.hp.hpl.jena.rdf.model.RDFNode; //导入方法依赖的package包/类
protected void searchDolceSuperClasses(Set<Resource> types) {
    Queue<Resource> queue = new LinkedList<Resource>(types);
    Resource classResource, superClass;
    RDFNode node;
    NodeIterator nodeIterator;
    Set<Resource> yagoSuperClasses = new HashSet<Resource>();
    Set<Resource> dolceSuperClasses = new HashSet<Resource>();
    boolean dolceClassFound = false;
    while (!queue.isEmpty()) {
        classResource = queue.poll();
        // If this resource is a DOLCE resource
        if (dolceClassModel.containsResource(classResource)) {
            dolceClassFound = true;
        } else {
            nodeIterator = classesModel.listObjectsOfProperty(classResource, RDFS.subClassOf);
            yagoSuperClasses.clear();
            dolceSuperClasses.clear();
            while (nodeIterator.hasNext()) {
                node = nodeIterator.next();
                if (node.isResource()) {
                    superClass = node.asResource();
                    if (dolceClassModel.containsResource(superClass)) {
                        dolceSuperClasses.add(superClass);
                    } else {
                        yagoSuperClasses.add(superClass);
                    }
                } else {
                    LOGGER.error("Expected a resource in the statement (" + classResource + ", rdfs:subClassOf, "
                            + node + "). Ignoring this statement.");
                }
            }

            // If a DOLCE class has been found
            if (dolceSuperClasses.size() > 0) {
                // add only the DOLCE classes and discard all others
                types.addAll(dolceSuperClasses);
                dolceClassFound = true;
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Added super classes of " + classResource.getURI() + " --> "
                            + Arrays.toString(dolceSuperClasses.toArray()));
                }
            } else {
                for (Resource r : yagoSuperClasses) {
                    // If they have not been found before (and already have
                    // been
                    // added to the queue)
                    if (!types.contains(r)) {
                        types.add(r);
                        queue.add(r);
                    }
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Added super classes of " + classResource.getURI() + " --> "
                                + Arrays.toString(yagoSuperClasses.toArray()));
                    }
                }
            }
        }
    }
    if (!dolceClassFound) {
        LOGGER.warn(
                "Couldn't find a DOLCE class for the following list of types: " + Arrays.toString(types.toArray()));
    }
}
 
开发者ID:dice-group,项目名称:Cetus,代码行数:64,代码来源:YagoBasedTypeSearcher.java


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