⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modelcom.java

📁 Jena推理机
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        while (members != null && members.hasNext()) {
            list = list.with( (RDFNode) members.next() );
        }
        
        return list;
    }
    
    
    /**
     * <p>Answer a new list containing the RDF nodes from the given array, in order</p>
     * @param members An array of RDFNodes that will be the members of the list
     * @return An RDF-encoded list 
     */
    public RDFList createList( RDFNode[] members ) {
        return createList( Arrays.asList( members ).iterator() );
    }
    
    public RDFNode getRDFNode( Node n )
        {   return asRDFNode( n ); }
    
    public Resource getResource( String uri )  
        { return IteratorFactory.asResource(makeURI(uri),this); }
    
    public Property getProperty( String uri )  
        {
        if (uri == null) throw new InvalidPropertyURIException( null );
        return IteratorFactory.asProperty( makeURI(uri), this );
        }
    
    public Property getProperty( String nameSpace,String localName )
        { return getProperty( nameSpace + localName ); }
    
    public Seq getSeq( String uri )  
        { return (Seq) IteratorFactory.asResource( makeURI( uri ),Seq.class, this); }
    
    public Seq getSeq( Resource r )  
        { return (Seq) r.as( Seq.class ); }
    
    public Bag getBag( String uri )  
        { return (Bag) IteratorFactory.asResource( makeURI( uri ),Bag.class, this ); }
    
    public Bag getBag( Resource r )  
        { return (Bag) r.as( Bag.class ); }
    
    static private Node makeURI(String uri) 
        { return uri == null ? Node.createAnon() : Node.createURI( uri ); }
    
    public Alt getAlt( String uri )  
        { return (Alt) IteratorFactory.asResource( makeURI(uri) ,Alt.class, this ); }
    
    public Alt getAlt( Resource r )  
        { return (Alt) r.as( Alt.class ); }
    
    public long size()  
        { return graph.size(); }

    public boolean isEmpty()
        { return graph.isEmpty(); }
        
    private void updateNamespace( Set set, Iterator it )
        {
        while (it.hasNext())
            {
            Node node = (Node) it.next();
            if (node.isURI())
                {
                String uri = node.getURI();
                String ns = uri.substring( 0, Util.splitNamespace( uri ) );
                // String ns = IteratorFactory.asResource( node, this ).getNameSpace();
                set.add( ns );
                }
            }
        }
        
    private Iterator listPredicates()
        { return getGraph().queryHandler().predicatesFor( Node.ANY, Node.ANY ); }
     
    private Iterator listTypes()
        {
        Set types = CollectionFactory.createHashedSet();
        ClosableIterator it = graph.find( null, RDF.type.asNode(), null );
        while (it.hasNext()) types.add( ((Triple) it.next()).getObject() );
        return types.iterator();
        }
     
    public NsIterator listNameSpaces()  {
        Set nameSpaces = CollectionFactory.createHashedSet();
        updateNamespace( nameSpaces, listPredicates() );
        updateNamespace( nameSpaces, listTypes() );
        return new NsIteratorImpl(nameSpaces.iterator(), nameSpaces);
    }
    
    private PrefixMapping getPrefixMapping()
        { return getGraph().getPrefixMapping(); }
    
    public boolean samePrefixMappingAs( PrefixMapping other )
        { return getPrefixMapping().samePrefixMappingAs( other ); }
        
    public PrefixMapping lock()
        {
        getPrefixMapping().lock();
        return this;
        }
        
    public PrefixMapping setNsPrefix( String prefix, String uri )
        { 
        getPrefixMapping().setNsPrefix( prefix, uri ); 
        return this;
        }
        
    public PrefixMapping removeNsPrefix( String prefix )
        {
        getPrefixMapping().removeNsPrefix( prefix );
        return this;
        }
    
    public PrefixMapping setNsPrefixes( PrefixMapping pm )
        { 
        getPrefixMapping().setNsPrefixes( pm );
        return this;
        }
        
    public PrefixMapping setNsPrefixes( Map map )
        { 
        getPrefixMapping().setNsPrefixes( map ); 
        return this;
        }
    
    public PrefixMapping withDefaultMappings( PrefixMapping other )
        {
        getPrefixMapping().withDefaultMappings( other );
        return this;
        }
        
    public String getNsPrefixURI( String prefix ) 
        { return getPrefixMapping().getNsPrefixURI( prefix ); }

    public String getNsURIPrefix( String uri )
        { return getPrefixMapping().getNsURIPrefix( uri ); }
                
    public Map getNsPrefixMap()
        { return getPrefixMapping().getNsPrefixMap(); }
        
    public String expandPrefix( String prefixed )
        { return getPrefixMapping().expandPrefix( prefixed ); }
        
    public String usePrefix( String uri )
        { return getPrefixMapping().shortForm( uri ); }
    
    public String qnameFor( String uri )
        { return getPrefixMapping().qnameFor( uri ); }
    
    public String shortForm( String uri )
        { return getPrefixMapping().shortForm( uri ); }
        
    /**
        Service method to update the namespaces of  a Model given the
        mappings from prefix names to sets of URIs.
        
        If the prefix maps to multiple URIs, then we discard it completely.
        
        @param the Model who's namespace is to be updated
        @param ns the namespace map to add to the Model      
    */
    public static void addNamespaces( Model m, Map ns )
        { 
        PrefixMapping pm = m;
        Iterator it  = ns.entrySet().iterator();
        while (it.hasNext())
            {
            Map.Entry e = (Map.Entry) it.next();
            String key = (String) e.getKey();
            Set  values = (Set) e.getValue();
            Set niceValues = CollectionFactory.createHashedSet();
            Iterator them = values.iterator();
            while (them.hasNext())
                {
                String uri = (String) them.next();
                if (PrefixMappingImpl.isNiceURI( uri )) niceValues.add( uri );
                }
            if (niceValues.size() == 1)
                pm.setNsPrefix( key, (String) niceValues.iterator().next() );
            }            
        }
        
    public StmtIterator listStatements()  
        { return IteratorFactory.asStmtIterator( GraphUtil.findAll( graph ), this); }

    /**
        add a Statement to this Model by adding its SPO components.
    */
    public Model add( Statement s )  
        {
        add( s.getSubject(), s.getPredicate(), s.getObject() );
        return this;
        }
    
    /**
        Add all the statements to the model by converting them to an array of corresponding
        triples and removing those from the underlying graph.
    */
    public Model add( Statement [] statements )
        {
        getBulkUpdateHandler().add( StatementImpl.asTriples( statements ) );
        return this;
        }
        
    protected BulkUpdateHandler getBulkUpdateHandler()
        { return getGraph().getBulkUpdateHandler(); }
        
    /**
        Add all the statements to the model by converting the list to an array of
        Statement and removing that.
    */
    public Model add( List statements )
        {
        getBulkUpdateHandler().add( asTriples( statements ) );
        return this;
        }
        
    private List asTriples( List statements )
        {
        List L = new ArrayList( statements.size() );
        for (int i = 0; i < statements.size(); i += 1) 
            L.add( ((Statement) statements.get(i)).asTriple() );
        return L;
        }
        
    private Iterator asTriples( StmtIterator it )
        { return new Map1Iterator( mapAsTriple, it ); }
        
    private Map1 mapAsTriple = new Map1()
        { public Object map1( Object s ) { return ((Statement) s).asTriple(); } };
        
    /**
        remove all the Statements from the model by converting them to triples and
        removing those triples from the underlying graph.        
    */ 
    public Model remove( Statement [] statements )
        {
        getBulkUpdateHandler().delete( StatementImpl.asTriples( statements ) );        
        return this;
        }
     
    /**
        Remove all the Statements from the model by converting the List to a
        List(Statement) and removing that.
    */
    public Model remove( List statements )
        {
        getBulkUpdateHandler().delete( asTriples( statements ) );
        return this;
        }
           
    public Model add( Resource s, Property p, RDFNode o )  {
        modelReifier.noteIfReified( s, p, o );
        graph.add( Triple.create( s.asNode(), p.asNode(), o.asNode() ) );
        return this;
    }
    
    public ReificationStyle getReificationStyle()
        { return modelReifier.getReificationStyle(); }
        
    /**
        @return an iterator which delivers all the ReifiedStatements in this model
    */
    public RSIterator listReifiedStatements()
        { return modelReifier.listReifiedStatements(); }

    /**
        @return an iterator each of whose elements is a ReifiedStatement in this
            model such that it's getStatement().equals( st )
    */
    public RSIterator listReifiedStatements( Statement st )
        { return modelReifier.listReifiedStatements( st ); }
                
    /**
        @return true iff this model has a reification of _s_ in some Statement
    */
    public boolean isReified( Statement s ) 
        { return modelReifier.isReified( s ); }
   
    /**
        get any reification of the given statement in this model; make
        one if necessary.
        
        @param s for which a reification is sought
        @return a ReifiedStatement that reifies _s_
    */
    public Resource getAnyReifiedStatement(Statement s) 
        { return modelReifier.getAnyReifiedStatement( s ); }
    
    /**
        remove any ReifiedStatements reifying the given statement
        @param s the statement who's reifications are to be discarded
    */
    public void removeAllReifications( Statement s ) 
        { modelReifier.removeAllReifications( s ); }
        
    public void removeReification( ReifiedStatement rs )
        { modelReifier.removeReification( rs ); }
    	
    /**
        create a ReifiedStatement that encodes _s_ and belongs to this Model.
    */
    public ReifiedStatement createReifiedStatement( Statement s )
        { return modelReifier.createReifiedStatement( s ); }
        
    public ReifiedStatement createReifiedStatement( String uri, Statement s )
        { return modelReifier.createReifiedStatement( uri, s ); }
    
    public boolean contains( Statement s )    
        { return graph.contains( s.asTriple() ); }
    
    public boolean containsResource( RDFNode r )
        { return graph.queryHandler().containsNode( r.asNode() ); }

    public boolean contains( Resource s, Property p ) 
        { return contains( s, p, (RDFNode) null );  }
    
    public boolean contains( Resource s, Property p, RDFNode o )
        { return graph.contains( asNode( s ), asNode( p ), asNode( o ) ); }
        
    public Statement getRequiredProperty( Resource s, Property p )  
        { Statement st = getProperty( s, p );
        if (st == null) throw new PropertyNotFoundException( p );
        return st; }
    
    public Statement getProperty( Resource s, Property p )
        {
        StmtIterator iter = listStatements( s, p, (RDFNode) null );
        try { return iter.hasNext() ? iter.nextStatement() : null; }
        finally { iter.close(); }
        }
    
    public static Node asNode( RDFNode x )
        { return x == null ? Node.ANY : x.asNode(); }
        
    private NodeIterator listObjectsFor( RDFNode s, RDFNode p )
        {
        ClosableIterator xit = graph.queryHandler().objectsFor( asNode( s ), asNode( p ) );
        return IteratorFactory.asRDFNodeIterator( xit, this );
        }

    private ResIterator listSubjectsFor( RDFNode p, RDFNode o )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -