本文整理汇总了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;
}
示例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);
}
示例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());
}
}
}
}
}
示例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());
}
}
}
}
示例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);
}
}
示例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;
}
示例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++;
}
示例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/"));
}
}
}
}
示例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/"));
}
}
}
}
示例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/"));
}
}
}
}
示例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.");
}
}
}
}
}
示例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()));
}
}