1 6 7 package com.hp.hpl.jena.rdf.model.impl; 8 9 import junit.framework.Assert; 10 11 import com.hp.hpl.jena.rdf.model.*; 12 import com.hp.hpl.jena.graph.*; 13 import com.hp.hpl.jena.reasoner.*; 14 import com.hp.hpl.jena.reasoner.rulesys.impl.WrappedReasonerFactory; 15 import com.hp.hpl.jena.shared.*; 16 import com.hp.hpl.jena.vocabulary.*; 17 18 25 public class InfModelSpec extends ModelSpecImpl 26 { 27 30 protected Resource reasonerResource; 31 protected Resource reasonerRoot; 32 protected ReasonerFactory factory; 33 34 38 public InfModelSpec( Resource root, Model description ) 39 { 40 super( root, description ); 41 Statement st = description.getRequiredProperty( null, JenaModelSpec.reasoner ); 42 Statement xx = description.listStatements( root, JenaModelSpec.reasonsWith, (RDFNode) null ).nextStatement(); 43 reasonerRoot = st.getSubject(); 44 Resource yy = xx.getResource(); 45 reasonerResource = st.getResource(); 46 factory = getReasonerFactory( st.getSubject(), description ); 47 } 48 49 55 public Model createModel() 56 { return createModel( maker.getGraphMaker().createGraph() ); } 57 58 62 public Model createModelOver( String name ) 63 { return createModel( maker.getGraphMaker().createGraph( name ) ); } 64 65 72 protected Model createModel( Graph base ) 73 { 74 Reasoner reasoner = factory.create( null ); 75 return new InfModelImpl( reasoner.bind( base ) ); 76 } 77 78 82 public Property getMakerProperty() 83 { return JenaModelSpec.maker; } 84 85 93 public Model addDescription( Model desc, Resource self ) 94 { 95 super.addDescription( desc, self ); 96 Resource r = reasonerRoot; 97 desc.add( self, JenaModelSpec.reasonsWith, r ); 98 desc.add( r, JenaModelSpec.reasoner, reasonerResource ); 99 new ModelExtract( notJMS ) .extractInto( desc, r, description ); 100 return desc; 101 } 102 103 private final static TripleBoundary notJMSTriple = new TripleBoundary() 104 { public boolean stopAt( Triple t ) { return !t.getPredicate().getNameSpace().equals( JenaModelSpec.baseURI ); }}; 105 106 private static final StatementBoundary notJMS = new StatementBoundary() 107 { 108 public boolean stopAt( Statement s ) { return notJMSTriple.stopAt( s.asTriple() ); } 109 public TripleBoundary asTripleBoundary( Model ignored ) { return notJMSTriple; } 110 }; 111 112 121 public static ReasonerFactory getReasonerFactory( Resource R, Model rs ) 122 { 123 StmtIterator r = rs.listStatements( R, JenaModelSpec.reasoner, (RDFNode) null ); 124 if (r.hasNext() == false) throw new NoReasonerSuppliedException(); 125 Resource rr = r.nextStatement().getResource(); 126 String rrs = rr.getURI(); 127 ReasonerFactory rf = ReasonerRegistry.theRegistry().getFactory( rrs ); 128 if (rf == null) throw new NoSuchReasonerException( rrs ); 129 return new WrappedReasonerFactory( rf, ((Resource) R.inModel( rs )) ); 130 } 131 } 132 133 134 | Popular Tags |