Java 类com.hp.hpl.jena.rdf.model.impl.ModelCom 实例源码

项目:parkjam    文件:FileGraph.java   
/**
    Construct a new FileGraph who's name is given by the specified File,
    If create is true, this is a new file, and any existing file will be destroyed;
    if create is false, this is an existing file, and its current contents will
    be loaded. The language code for the file is supplied.

    @param f the File naming the associated file-system file
    @param lang the language string for the file
    @param create true to create a new one, false to read an existing one
    @param strict true to throw exceptions for create: existing, open: not found
    @param style the reification style for the graph
*/
public FileGraph( NotifyOnClose notify, File f, String lang, boolean create, boolean strict, ReificationStyle style )
    {
    super( style );
    this.name = f;
    this.notify = notify;
    this.model = new ModelCom( this );
    this.lang = lang;
    if (create)
        { if (f.exists() && strict) throw new AlreadyExistsException( f.toString() ); }
    else
        readModel( this.model, strict );
    }
项目:oro-server    文件:PartialStatement.java   
/** Creates a partial statement from a partial triplet (subject, predicate, object).
 * 
 * At least one of the parameter is assumed to be null.
 * 
 * @param subject The subject of the statement
 * @param predicate The predicate of the statement
 * @param object The object of the statement
 * @param model The ontology this partial statement refers to.
 */
public PartialStatement(Resource subject, Property predicate, RDFNode object, ModelCom model) {

    stmtTokens = new ArrayList<String>();

    if (subject == null) {
        stmtTokens.add("?subject");
        subject = model.createResource("nullSubject");
    }
    else
        stmtTokens.add(Namespaces.toLightString(subject));

    if (predicate == null) {
        stmtTokens.add("?predicate");
        predicate = model.createProperty("nullPredicate");
    }
    else
        stmtTokens.add(Namespaces.toLightString(predicate));

    if (object == null) {
        stmtTokens.add("?object");
        object = model.createResource("nullObject");
    }
    else
        stmtTokens.add(Namespaces.toLightString(object));

    baseStmt = new StatementImpl(subject, predicate, object, model);
}
项目:oro-server    文件:PartialStatement.java   
/**
 * Create a new partial statement from its string representation.<br/>
 * Works as {@link OpenRobotsOntology#createStatement(String)} except at least one variable, prepended with a "?", is expected.</br>
 * 
 * This class implements {@link Statement}, but the {@link #getSubject()}, {@link #getPredicate()} and {@link #getObject()} method will return {@code null} if the corresponding part of the statement is unbounded. 
 * 
 * @param partialStatement The string representing the partial statement. For example, {@code "?mysterious oro:objProperty2 ?object"} or {@code "?subject oro:dataProperty1 true"} are valid.
 * @param model The ontology this partial statement refers to.
 * @throws IllegalStatementException Currently thrown only if the statement doesn't contain three tokens.
 * @see OpenRobotsOntology#createStatement(String) Syntax details
 */
public PartialStatement(String partialStatement, ModelCom model) throws IllegalStatementException {

    Resource subject = null;
    Property predicate = null;
    RDFNode object = null;

    stmtTokens = Helpers.tokenize(partialStatement.trim(), ' ');

    if (stmtTokens.size() != 3)
        throw new IllegalStatementException("Three tokens are expected in a partial statement, " + stmtTokens.size() + " found in " + partialStatement + ".");


    //checks that at least one token starts with a "?".
    if (!((stmtTokens.get(0).length() > 0 && stmtTokens.get(0).charAt(0) == '?') || (stmtTokens.get(1).length() > 0 && stmtTokens.get(1).charAt(0) == '?') || (stmtTokens.get(2).length() > 0 && stmtTokens.get(2).charAt(0) == '?')) )
        throw new IllegalStatementException("At least one token should be marked as unbounded (starting with a \"?\").");

    if (stmtTokens.get(0).length() == 0 || stmtTokens.get(0).charAt(0) != '?')
        subject = model.getResource(Namespaces.format(stmtTokens.get(0)));
    else
        subject = model.createResource("nullSubject"); //if the subject is unbounded (a variable), creates an "nullSubject" resource to replace the subject.

    if (stmtTokens.get(1).length() == 0 || stmtTokens.get(1).charAt(0) != '?')
        predicate = model.getProperty(Namespaces.format(stmtTokens.get(1)));
    else
        predicate = model.createProperty("nullPredicate"); //if the predicate is unbounded (a variable), creates an "nullPredicate" property to replace the predicate.


    if (stmtTokens.get(2).length() == 0 || stmtTokens.get(2).charAt(0) != '?')
    {
        object = Helpers.parseLiteral(stmtTokens.get(2), model);                
        assert(object!=null);
    }
    else
        object = model.createResource("nullObject"); //if the object is unbounded (a variable), creates an "nullObject" object to replace the object.

    baseStmt = new StatementImpl(subject, predicate, object, model);

}
项目:D2RQ-Update    文件:ExtendedIteratorFactory.java   
/**
 * <p>Method that creates an iterator of resources</p>
 * @param i - an iterator of resources as input
 * @param m - the underlying model to use in the mapping
 * @return a ResIterator
 */
public static ResIterator asResIterator( Iterator<Resource> i, final ModelCom m ) 
{
    Map1<Resource, Resource> asResource = new Map1<Resource, Resource>() 
    { 
        public Resource map1( Resource o ) 
        { return (Resource) m.asRDFNode( o.asNode() ); }
    };
    return new ResIteratorImpl( WrappedIterator.create( i ).mapWith( asResource ), null );
}
项目:D2RQ-Update    文件:ExtendedIteratorFactory.java   
/**
 * <p>Method that creates an iterator of rdf nodes</p>
 * @param i - an iterator of rdf nodes as input
 * @param m - the underlying model to use in the mapping
 * @return a NodeIterator
 */
static public NodeIterator asRDFNodeIterator( Iterator<RDFNode> i, final ModelCom m ) 
   {      
    Map1<RDFNode, RDFNode> asRDFNode = new Map1<RDFNode, RDFNode>() 
       { 
        public RDFNode map1( RDFNode o ) 
        { return m.asRDFNode( o.asNode() ); }
    };
    return new NodeIteratorImpl( WrappedIterator.create( i ).mapWith( asRDFNode ), null );
   }
项目:OntoMapper    文件:StatementsPair.java   
public StatementPattern(Resource subject, Property predicate, RDFNode object, ModelCom model){
    this(subject, predicate, object, model, false, false, false);
}
项目:OntoMapper    文件:StatementsPair.java   
public StatementPattern(Resource subject, Property predicate, RDFNode object, ModelCom model, boolean anySubject, boolean anyPredicate, boolean anyObject ) {
    super(subject, predicate, object, model);
    initializeWildcard(anySubject, anyPredicate, anyObject);
}
项目:oro-server    文件:OpenRobotsOntology.java   
public Statement createStatement(String statement) throws IllegalStatementException {

    Resource subject;
    Property predicate;
    RDFNode object;

    List<String> tokens_statement = Helpers.tokenize(statement.trim(), ' ');

    if (tokens_statement.size() != 3)
        throw new IllegalStatementException(
                "Three tokens are expected in a statement, " +  
                tokens_statement.size() + " found in " + statement + ".");

    //expand the namespaces for subject and predicate.
    for (int i = 0; i<2; i++){
        tokens_statement.set(i, Namespaces.format(tokens_statement.get(i)));
    }


    subject = onto.getResource(tokens_statement.get(0));
    predicate = onto.getProperty(tokens_statement.get(1));

    //Handle objects

    object = Helpers.parseLiteral(tokens_statement.get(2), (ModelCom)onto);


    assert(object!=null);

    Statement s =new StatementImpl(subject, predicate, object);

    return s; 

}
项目:oro-server    文件:OpenRobotsOntology.java   
public PartialStatement createPartialStatement(String statement) throws IllegalStatementException {

    PartialStatement p = new PartialStatement(statement, (ModelCom)getModel());

    return p;
}