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

📄 modelcom.java

📁 semantic web framework
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }
    }
    public Statement createStatement(Resource r, Property p, String o,
                                     boolean wellFormed) throws RDFException {
        return createStatement(r, p, new LiteralImpl(o, wellFormed));
    }

    public Statement createStatement(Resource r, Property p, String o, String l)
      throws RDFException {
        return createStatement(r, p, new LiteralImpl(o,l));
    }
    public Statement createStatement(Resource r, Property p, String o, String l,
                                     boolean wellFormed) throws RDFException {
        return createStatement(r, p, new LiteralImpl(o,l,wellFormed));
    }
    public Bag createBag() throws RDFException {
        return createBag(null);
    }
    public Alt createAlt() throws RDFException {
        return createAlt(null);
    }
    public Seq createSeq() throws RDFException {
        return createSeq(null);
    }

    public Resource getResource(String uri) throws RDFException {
        return store.getResource(uri, this);
    }

    public Property getProperty(String uri) throws RDFException {
        return store.getProperty(uri, this);
    }

    public Property getProperty(String nameSpace,String localName)
      throws RDFException {
        return store.getProperty(nameSpace, localName, this);
    }

    public Bag getBag(String uri) throws RDFException {
      return store.getBag(uri, this);
    }
    public Bag getBag(Resource r) throws RDFException {
        return store.getBag(r, this);
    }

    public Alt getAlt(String uri) throws RDFException {
        return store.getAlt(uri, this);
    }

    public Alt getAlt(Resource r) throws RDFException {
        return store.getAlt(r, this);
    }

    public Seq getSeq(String uri) throws RDFException {
        return store.getSeq(uri, this);
    }
    public Seq getSeq(Resource r) throws RDFException {
        return store.getSeq(r, this);
    }

    public long size() throws RDFException {
        return store.size();
    }

    public ResIterator listSubjects() throws RDFException {
        return store.listSubjects();
    }

    public NsIterator listNameSpaces() throws RDFException {
        return store.listNameSpaces();
    }

    public StmtIterator listStatements() throws RDFException {
        return new StmtIteratorImpl(store.list(), null);
    }

    public StmtIterator listReifiedStatements() throws RDFException {
        Vector reifiedStatements = new Vector();
        Iterator iter = store.list();
        Object subject;
        while (iter.hasNext()) {
            subject = ((Statement) iter.next()).getSubject();
            if (subject instanceof Statement) {
                reifiedStatements.add(subject);
            }
        }
        if (iter instanceof ClosableIterator) {
            ((ClosableIterator) iter).close();
        }
        return new StmtIteratorImpl(reifiedStatements.iterator(),
                                    reifiedStatements);
    }

    public Model add(Statement s) throws RDFException {
        if (! (s instanceof StatementImpl)
          || (((StatementImpl)s).getModel() != this) ) {
            s = new StatementImpl(s.getSubject(),
                                  s.getPredicate(),
                                  s.getObject(),
                                  this);
        }
        store.add(s);
        return this;
    }

    public Model remove(Statement s) throws RDFException {
        store.remove(s);
        return this;
    }

    public boolean contains(Statement s) throws RDFException {
        return store.contains(s);
    }

    public boolean contains(Resource s, Property p) throws RDFException {
        return store.contains(s, p);
    }

    public boolean contains(Resource s, Property p, RDFNode o)
      throws RDFException {
       return contains(new StatementImpl(s, p, o));
    }

    public boolean isReified(Statement s) throws RDFException {
        StmtIterator iter = null;
        try {
            iter = listStatements(new SelectorImpl(s, null, (RDFNode) null));
            if (iter.hasNext()) {
                return true;
            }
            iter = listStatements(new SelectorImpl(null, null, s));
            return iter.hasNext();
        } finally {
            iter.close();
        }
    }

    public Statement getProperty(Resource s,Property p) throws RDFException {
        StmtIterator iter = null;
        try {
            iter = listStatements(new SelectorImpl(s, p, (RDFNode) null));
            if (iter.hasNext()) {
                return iter.next();
            } else {
                throw new RDFException(RDFException.PROPERTYNOTFOUND);
            }
        } finally {
            iter.close();
        }
    }

    public ResIterator listSubjectsWithProperty(Property p)
    throws RDFException {
        HashSet subjects = new HashSet();
        Iterator iter = store.listByPredicate(p);
        Statement stmt;
        try {
            while (iter.hasNext()) {
                stmt = (Statement)(iter.next());
                if (stmt.getPredicate().equals(p)) {
                    subjects.add(stmt.getSubject());
                }
            }
        } finally {
            if (iter instanceof ClosableIterator) {
                ((ClosableIterator) iter).close();
            }
        }
        return new ResIteratorImpl(subjects.iterator(), subjects);
    }

    public ResIterator listSubjectsWithProperty(Property p, RDFNode o)
    throws RDFException {
        HashSet subjects = new HashSet();
        Iterator iter = store.list(null, p, o);
        Statement stmt;
        try {
            while (iter.hasNext()) {
                stmt = (Statement)(iter.next());
// we need to check here because ModelMem does not return an exact match
// maybe this should be fixed @@FIX
                if (stmt.getPredicate().equals(p)
                  && stmt.getObject().equals(o)) {
                    subjects.add(stmt.getSubject());
                }
            }
        } finally {
            if (iter instanceof ClosableIterator) {
                ((ClosableIterator) iter).close();
            }
        }
        return new ResIteratorImpl(subjects.iterator(), subjects);
    }

    public NodeIterator listObjects() throws RDFException {
        HashSet objects = new HashSet();
        Iterator iter = store.list();
        Statement stmt = null;
        try {
            while (iter.hasNext()) {
                objects.add(((Statement) iter.next()).getObject());
            }
        } finally {
            if (iter instanceof ClosableIterator) {
                ((ClosableIterator) iter).close();
            }
        }
        return new NodeIteratorImpl(objects.iterator(), objects);
    }

    public NodeIterator listObjectsOfProperty(Property p) throws RDFException {
        HashSet objects = new HashSet();
        Iterator iter = store.listByPredicate(p);
        try {
            while (iter.hasNext()) {
                Statement stmt = (Statement) iter.next();
                objects.add(stmt.getObject());
            }
        } finally {
            if (iter instanceof ClosableIterator) {
                ((ClosableIterator) iter).close();
            }
        }
        return new NodeIteratorImpl(objects.iterator(), objects);
    }

    public NodeIterator listObjectsOfProperty(Resource s, Property p)
      throws RDFException {
        HashSet objects = new HashSet();
        Iterator iter = store.list(s, p, null);
        try {
            Statement stmt = null;
            while (iter.hasNext()) {
                stmt = (Statement) iter.next();
                if (stmt.getPredicate().equals(p))
                {
                    objects.add(stmt.getObject());
                }
            }
        } finally {
            if (iter instanceof ClosableIterator) {
                ((ClosableIterator) iter).close();
            }
        }
        return new NodeIteratorImpl(objects.iterator(), objects);
    }

    public StmtIterator listStatements(Selector selector)
      throws RDFException {
        Iterator iter;

        if (selector instanceof SelectorImpl) {
            SelectorImpl s = (SelectorImpl) selector;
            iter = store.list(s.getSubject(),
                              s.getPredicate(),
                              s.getObject());
        } else {
            iter = store.list();
        }

        if (iter == null) {
            return new StmtIteratorImpl((new HashSet()).iterator(), null);
        }
        return listStatements(selector, iter);
    }

    protected StmtIterator listStatements(Selector s, Iterator iter)
      throws RDFException {
        Vector matching = new Vector();
        Statement stmt;
        while (iter.hasNext()) {
            stmt = (Statement) iter.next();
            try {
                if (s.test(stmt)) {
                    matching.add(stmt);
                }
            } catch (Exception e) {
                if (iter instanceof ClosableIterator) {
                    ((ClosableIterator)iter).close();
                }
                throw new RDFException(RDFException.SELECTOREXCEPTION, e);
            }
        }
        return new StmtIteratorImpl(matching.iterator(), matching);
    }

    public Model begin() throws RDFException {
        throw new RDFException(RDFException.UNSUPPORTEDOPERATION);
    }

    public Model abort() throws RDFException {
        throw new RDFException(RDFException.UNSUPPORTEDOPERATION);
    }

    public Model commit() throws RDFException {
        throw new RDFException(RDFException.UNSUPPORTEDOPERATION);
    }

    public boolean independent() {
        return true;
    }
    public Resource createResource() throws RDFException {
        return store.createResource(this);
    }

    public Resource createResource(String uri) throws RDFException {
        return store.createResource(uri, this);
    }

    public Property createProperty(String uri) throws RDFException {
        return store.createProperty(uri, this);
    }
    public Property createProperty(String nameSpace, String localName)
    throws RDFException {
        return store.createProperty(nameSpace, localName, this);
    }

    public Statement createStatement(Resource r, Property p, RDFNode o)
    throws RDFException {
        return new StatementImpl(r, p, o, this);
    }

    public Bag createBag(String uri) throws RDFException {
        Bag bag = store.createBag(uri, this);
        bag.addProperty(RDF.type, RDF.Bag);
        return bag;
    }
    public Alt createAlt(String uri) throws RDFException {
        Alt alt = store.createAlt(uri, this);
        alt.addProperty(RDF.type, RDF.Alt);
        return alt;
    }
    public Seq createSeq(String uri) throws RDFException {
        Seq seq = store.createSeq(uri, this);
        seq.addProperty(RDF.type, RDF.Seq);
        return seq;
    }

    public NodeIterator listContainerMembers(Container cont,
                                             NodeIteratorFactory f)
                                                  throws RDFException {
        Iterator iter = store.listBySubject(cont);
        Statement    stmt;
        String       rdfURI = RDF.getURI();
        Vector       result = new Vector();
        int          maxOrdinal = 0;
        int          ordinal;
        while (iter.hasNext()) {
            stmt = (Statement) iter.next();
            ordinal = stmt.getPredicate().getOrdinal();
            if (stmt.getSubject().equals(cont) && ordinal != 0) {
                if (ordinal > maxOrdinal) {
                    maxOrdinal = ordinal;
                    result.setSize(ordinal);
                }
                result.setElementAt(stmt, ordinal-1);
            }
        }
        if (iter instanceof ClosableIterator) {
            ((ClosableIterator) iter).close();
        }
        try {
             return f.createIterator(result.iterator(), result, cont);
        } catch (Exception e) {
            throw new RDFException(e);
        }
    }

    public int containerSize(Container cont) throws RDFException {
        int result = 0;
        Iterator iter = store.listBySubject(cont);
        Property     predicate;
        Statement    stmt;
        String       rdfURI = RDF.getURI();
        while (iter.hasNext()) {
            stmt = (Statement) iter.next();
            predicate = stmt.getPredicate();
            if (stmt.getSubject().equals(cont)
             && predicate.getOrdinal() != 0
               ) {
                result++;
            }
        }
        if (iter instanceof ClosableIterator) {
            ((ClosableIterator) iter).close();
        }
        return result;
    }

    public int containerIndexOf(Container cont, RDFNode n) throws RDFException {
        int result = 0;
        Iterator iter = store.listBySubject(cont);
        Property     predicate;
        Statement    stmt;
        String       rdfURI = RDF.getURI();
        while (iter.hasNext()) {
            stmt = (Statement) iter.next();
            predicate = stmt.getPredicate();
            if (stmt.getSubject().equals(cont)
             && predicate.getOrdinal() != 0
             && n.equals(stmt.getObject())
              ) {
                result = predicate.getOrdinal();
                break;
            }
        }
        if (iter instanceof ClosableIterator) {
            ((ClosableIterator) iter).close();
        }
        return result;
    }

   public boolean containerContains(Container cont, RDFNode n)
    throws RDFException {
        return containerIndexOf(cont, n) != 0;
    }

    public Resource convert(Resource r) throws RDFException {
        if (r.getModel() == this) {
            return r;
        } else {
            return ((ResourceI)r).port(this);
        }
    }

    public Property convert(Property p) throws RDFException {
        if (p.getModel() == this) {
            return p;
        } else {
            return (Property) ((ResourceI)p).port(this);
        }
    }

    public RDFNode convert(RDFNode n) throws RDFException {
        if (n instanceof Property) {
            return convert((Property) n);
        } else if (n instanceof Resource) {
            return convert((Resource) n);
        } else {
            return n;
        }
    }

    public boolean equals(Object model ) {
        try {
            if (model==null || ! (model instanceof Model)) {
                return false;
            }
            return //match( (Model) model);
            ModelMatcher.equals(this, (Model) model);
        } catch (RDFException e) {
            throw new RDFError(e);
        }
    }

    public void close() {
        store.close();
    }
}

⌨️ 快捷键说明

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