本文整理汇总了Java中org.openrdf.model.Model.size方法的典型用法代码示例。如果您正苦于以下问题:Java Model.size方法的具体用法?Java Model.size怎么用?Java Model.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.model.Model
的用法示例。
在下文中一共展示了Model.size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstances
import org.openrdf.model.Model; //导入方法依赖的package包/类
public static Model getInstances( URI subtype, URI predtype, URI objtype,
Collection<URI> propsToInclude, IEngine engine ) {
// round one: get the relationships themselves
String query = "CONSTRUCT { ?s ?p ?o } WHERE {\n"
+ " ?s a|rdfs:subClassOf+ ?subtype .\n"
+ " ?o a|rdfs:subClassOf+ ?objtype .\n"
+ " ?p a|rdfs:subPropertyOf+ ?predtype .\n"
+ " FILTER( ?s != ?subtype && ?o != ?objtype ) .\n"
+ " ?s ?p ?o .\n"
+ "}";
ModelQueryAdapter mqa = new ModelQueryAdapter( query );
mqa.bind( "subtype", subtype );
mqa.bind( "objtype", objtype );
mqa.bind( "predtype", predtype );
mqa.useInferred( true );
Model model = engine.constructNoEx( mqa );
// we get inferred rel types as well as declared types, so if we have
// both, use the declared type
List<Statement> removers = new ArrayList<>();
for ( Statement s : model ) {
URI subj = URI.class.cast( s.getSubject() );
URI obj = URI.class.cast( s.getObject() );
Model filts = model.filter( subj, null, obj );
if ( filts.size() > 1 ) {
removers.add( new StatementImpl( subj, predtype, obj ) );
}
}
model.removeAll( removers );
// round two: get properties for the relationships if they exist
if ( !( null == propsToInclude || propsToInclude.isEmpty() ) ) {
String propq = "CONSTRUCT { ?p ?prop ?propval } WHERE {\n"
+ " ?p rdfs:subPropertyOf+ ?predtype ; ?prop ?propval .\n"
+ " VALUES ?prop {" + Utility.implode( propsToInclude ) + "}.\n"
+ "}";
ModelQueryAdapter propqa = new ModelQueryAdapter( propq );
propqa.bind( "predtype", predtype );
propqa.setModel( model );
propqa.useInferred( false );
engine.constructNoEx( propqa );
}
return model;
}