1 6 7 package com.hp.hpl.jena.util; 8 9 import com.hp.hpl.jena.rdf.model.*; 10 import com.hp.hpl.jena.graph.*; 11 import com.hp.hpl.jena.util.iterator.*; 12 13 import java.util.*; 14 15 25 public class ModelQueryUtil 26 { 27 private ModelQueryUtil() 28 {} 29 30 public static ExtendedIterator queryBindingsWith 31 ( final Model model, Model query, Resource [] variables ) 32 { 33 Map1 mm = new Map1() 34 { public Object map1( Object x ) { return mappy( model, x ); } }; 35 QueryMapper qm = new QueryMapper( query, variables ); 36 return 37 qm.getQuery().executeBindings( model.getGraph(), qm.getVariables() ) 38 .mapWith( mm ) 39 ; 40 } 41 42 public static RDFNode asRDF( Model m, Node n ) 43 { return m.asRDFNode( n ); } 44 45 public static List mappy( Model m, Object x ) 46 { 47 List L = (List) x; 48 ArrayList result = new ArrayList( L.size() ); 49 for (int i = 0; i < L.size(); i += 1) result.add( asRDF( m, (Node) L.get( i ) ) ); 50 return result; 51 } 52 53 } 54 55 56 | Popular Tags |