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


Java InfModel.listStatements方法代码示例

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


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

示例1: runInference

import com.hp.hpl.jena.rdf.model.InfModel; //导入方法依赖的package包/类
private Model runInference(Model data, URL rules, int lineLength, int maxLineLength) throws IOException
{	
	Reasoner reasoner = new GenericRuleReasoner(Rule.rulesFromURL(rules.toString()));
	InfModel inf = ModelFactory.createInfModel(reasoner, data);
	
	// Break long literals (more than lineLength chars) using carriage returns
	Model remove = ModelFactory.createDefaultModel();
	Model add = ModelFactory.createDefaultModel();
	Selector sel = new SimpleSelector(null, null, (String)null);
	for(StmtIterator sIt = inf.listStatements(sel); sIt.hasNext();)
	{
		Statement s = sIt.nextStatement();
		if(!s.getObject().isLiteral())
			continue;
		String l = s.getString();
		
		String lp = paginate(l, lineLength, maxLineLength);
		if (lp.length() != l.length())
		{
			remove.add(s);
			add.add(s.getSubject(), s.getPredicate(), lp, s.getLanguage());
		}
	}
	
	inf.remove(remove);
	inf.add(add);
	
	return inf;
}
 
开发者ID:rhizomik,项目名称:redefer-rdf2svg,代码行数:30,代码来源:RenderRDF.java

示例2: main

import com.hp.hpl.jena.rdf.model.InfModel; //导入方法依赖的package包/类
public static void main(String args[])
{
	String filename = "example6.rdf";

	// Create an empty model
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);

	// Use the FileManager to find the input file
	InputStream in = FileManager.get().open(filename);

	if (in == null)
		throw new IllegalArgumentException("File: "+filename+" not found");

	// Read the RDF/XML file
	model.read(in, null);

	// ** TASK 7.1: List all individuals of "Person" **
	System.out.println("\nTASK 7.1 - List all individuals of Person\n");
	OntClass person = model.getOntClass(ns+"Person");
	ExtendedIterator<? extends OntResource> itr = person.listInstances();
	while(itr.hasNext()){
		Individual persons = (Individual) itr.next();
		System.out.println("Person : " + persons);	
	}
	// ** TASK 7.2: List all subclasses of "Person" **
	System.out.println("\nTASK 7.2 - List all subclasses of Person\n");
	itr = person.listSubClasses(false);
	while (itr.hasNext()) {
		OntClass ontClass = (OntClass) itr.next();
		System.out.println("Subclass : " + ontClass);
	}

	// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. ** 
	// ** TIP: you need some inference... **
	System.out.println("\nTASK 7.3 - Make the necessary changes to get as well indirect instances and subclasses\n");
	Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
	reasoner = reasoner.bindSchema(model);
	reasoner.setDerivationLogging(true);
	InfModel inf = ModelFactory.createInfModel(reasoner, model);
	StmtIterator i = inf.listStatements(person, null, (RDFNode) null);
	while(i.hasNext()){
		Statement s = i.nextStatement();
		System.out.println("Statement: \n" + s.asTriple()); //turtle format
	}
}
 
开发者ID:FacultadInformatica-LinkedData,项目名称:Curso2014-2015,代码行数:46,代码来源:Task07_Nestor_Lopez.java

示例3: main

import com.hp.hpl.jena.rdf.model.InfModel; //导入方法依赖的package包/类
public static void main( String[] args )
{

	// load some data that uses RDFS
	Model data = FileManager.get().loadModel("file:data/input/turtle/ex2-data.ttl");
	
	// InfModel infmodel = ModelFactory.createRDFSModel(data);
	
	Reasoner reasoner = ReasonerRegistry.getRDFSReasoner();
	reasoner.setParameter(ReasonerVocabulary.PROPsetRDFSLevel, 
               ReasonerVocabulary.RDFS_DEFAULT);
	InfModel infmodel = ModelFactory.createInfModel(reasoner, data );
	

	StmtIterator sIter = infmodel.listStatements();
	
	
	while( sIter.hasNext() )
	{
		Statement stmt = sIter.nextStatement();
		System.out.println( PrintUtil.print(stmt));
	}		
	
	
	System.out.println( "\n\n******************************\n\n" );

	Resource O = infmodel.createResource( "http://www.example.com/shop#Shirts" );
	
	/*
	Selector selector = new SimpleSelector((Resource)null, (Property)null, O);
	
	StmtIterator siter2 = infmodel.listStatements( selector );
	
	
	while( siter2.hasNext() )
	{
		Statement stmt = siter2.nextStatement();
		System.out.println( PrintUtil.print(stmt));
	}
	*/
	
	System.out.println( "\n\n******************************\n\n" );

	/*
	Property P = infmodel.createProperty( "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" );
	Selector selector2 = new SimpleSelector((Resource)null, (Property)P, O);
	
	StmtIterator siter3 = infmodel.listStatements( selector2 );
	
	
	while( siter3.hasNext() )
	{
		Statement stmt = siter3.nextStatement();
		System.out.println( PrintUtil.print(stmt));
	}		
	*/
	
	System.out.println( "done" );
	
}
 
开发者ID:fogbeam,项目名称:JenaTutorial,代码行数:61,代码来源:ReadRDF_ListTriplesWithSelector.java


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