Search in sources :

Example 36 with Value

use of org.openrdf.model.Value in project vcell by virtualcell.

the class VCMetaDataMiriamManager method getDublinCoreDateMap.

// this is not yet cached.
public Map<Identifiable, Map<DateQualifier, Set<DublinCoreDate>>> getDublinCoreDateMap() {
    Map<Identifiable, Map<DateQualifier, Set<DublinCoreDate>>> map = new HashMap<Identifiable, Map<DateQualifier, Set<DublinCoreDate>>>();
    Set<Entry> allEntries = vcMetaData.getRegistry().getAllEntries();
    Graph rdfData = vcMetaData.getRdfData();
    for (Entry entry : allEntries) {
        Resource resource = entry.getResource();
        if (resource != null) {
            Identifiable identifiable = entry.getIdentifiable();
            Map<DateQualifier, Set<DublinCoreDate>> qualifierDateMap = new HashMap<DateQualifier, Set<DublinCoreDate>>();
            for (DublinCoreQualifier.DateQualifier dateQualifier : AnnotationQualifiers.DC_date_all) {
                Set<DublinCoreDate> dateStrings = new HashSet<DublinCoreDate>();
                Iterator<Statement> stmtIter = rdfData.match(resource, dateQualifier.getProperty(), null);
                while (stmtIter.hasNext()) {
                    Statement statement = stmtIter.next();
                    Value dateObject = statement.getObject();
                    if (dateObject instanceof Literal) {
                        Literal dateLiteral = (Literal) dateObject;
                        String dateString = dateLiteral.stringValue();
                        dateStrings.add(new DublinCoreDate(dateString));
                    }
                }
                if (!dateStrings.isEmpty()) {
                    qualifierDateMap.put(dateQualifier, dateStrings);
                }
            }
            if (!qualifierDateMap.isEmpty()) {
                map.put(identifiable, qualifierDateMap);
            }
        }
    }
    return map;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) DublinCoreDate(org.vcell.sybil.models.dublincore.DublinCoreDate) HashMap(java.util.HashMap) Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource) DateQualifier(org.vcell.sybil.models.dublincore.DublinCoreQualifier.DateQualifier) Identifiable(org.vcell.util.document.Identifiable) Entry(cbit.vcell.biomodel.meta.registry.Registry.Entry) Graph(org.openrdf.model.Graph) DateQualifier(org.vcell.sybil.models.dublincore.DublinCoreQualifier.DateQualifier) DublinCoreQualifier(org.vcell.sybil.models.dublincore.DublinCoreQualifier) Literal(org.openrdf.model.Literal) Value(org.openrdf.model.Value) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Example 37 with Value

use of org.openrdf.model.Value in project vcell by virtualcell.

the class IndexedGraph method match.

public Iterator<Statement> match(Resource subject, URI predicate, Value object, Resource... contexts) {
    Iterator<Statement> iterator = new RDFGraphMatchIterator(this, subject, predicate, object);
    if (subject != null) {
        if (predicate != null) {
            if (object != null) {
                Statement statement = getValueFactory().createStatement(subject, predicate, object);
                if (statements.contains(statement)) {
                    iterator = new IndexedGraphIterator(this, new IterOfOne<Statement>(statement));
                } else {
                    iterator = new IterOfNone<Statement>();
                }
            } else {
                Set<Statement> matches = spMap.get(new ListOfTwo<Value>(subject, predicate));
                iterator = matches != null ? new IndexedGraphIterator(this, matches.iterator()) : new IterOfNone<Statement>();
            }
        } else {
            if (object != null) {
                Set<Statement> matches = soMap.get(new ListOfTwo<Value>(subject, object));
                iterator = matches != null ? new IndexedGraphIterator(this, matches.iterator()) : new IterOfNone<Statement>();
            } else {
                Set<Statement> matches = sMap.get(subject);
                iterator = matches != null ? new IndexedGraphIterator(this, matches.iterator()) : new IterOfNone<Statement>();
            }
        }
    } else {
        if (predicate != null) {
            if (object != null) {
                Set<Statement> matches = poMap.get(new ListOfTwo<Value>(predicate, object));
                iterator = matches != null ? new IndexedGraphIterator(this, matches.iterator()) : new IterOfNone<Statement>();
            } else {
                Set<Statement> matches = pMap.get(predicate);
                iterator = matches != null ? new IndexedGraphIterator(this, matches.iterator()) : new IterOfNone<Statement>();
            }
        } else {
            if (object != null) {
                Set<Statement> matches = oMap.get(object);
                iterator = matches != null ? new IndexedGraphIterator(this, matches.iterator()) : new IterOfNone<Statement>();
            } else {
                iterator = new IndexedGraphIterator(this, statements.iterator());
            }
        }
    }
    return iterator;
}
Also used : IterOfOne(org.sbpax.util.iterators.IterOfOne) Statement(org.openrdf.model.Statement) IterOfNone(org.sbpax.util.iterators.IterOfNone) Value(org.openrdf.model.Value)

Example 38 with Value

use of org.openrdf.model.Value in project vcell by virtualcell.

the class OntologyInfo method writeHasObjectProperty.

public static void writeHasObjectProperty(Graph graph, PrintStream out, Resource resource, URI property, String intro) {
    Iterator<Statement> iter = graph.match(resource, property, null);
    Set<Resource> resources = new HashSet<Resource>();
    while (iter.hasNext()) {
        Value superClassNode = iter.next().getObject();
        if (superClassNode instanceof Resource) {
            resources.add((Resource) superClassNode);
        }
    }
    if (resources.size() > 0) {
        out.println("  " + intro + ": " + resourcesToString(resources));
    }
}
Also used : Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource) Value(org.openrdf.model.Value) HashSet(java.util.HashSet)

Example 39 with Value

use of org.openrdf.model.Value in project vcell by virtualcell.

the class OntologyInfo method writeComments.

public static void writeComments(Graph graph, PrintStream out, Resource resource) {
    Iterator<Statement> iter = graph.match(resource, RDFS.COMMENT, null);
    while (iter.hasNext()) {
        Value commentNode = iter.next().getObject();
        if (commentNode instanceof Literal) {
            Literal commentLiteral = (Literal) commentNode;
            String comment = commentLiteral.stringValue();
            if (comment != null && comment != "") {
                out.println("  Comment: " + comment);
            }
        }
    }
}
Also used : Statement(org.openrdf.model.Statement) Literal(org.openrdf.model.Literal) Value(org.openrdf.model.Value)

Example 40 with Value

use of org.openrdf.model.Value in project vcell by virtualcell.

the class OntologyInfo method writeSuperClasses.

public static void writeSuperClasses(Graph graph, PrintStream out, Resource resource) {
    Iterator<Statement> iter = graph.match(resource, RDFS.SUBCLASSOF, null);
    Set<Resource> resources = new HashSet<Resource>();
    while (iter.hasNext()) {
        Value superClassNode = iter.next().getObject();
        if (superClassNode instanceof Resource) {
            resources.add((Resource) superClassNode);
        }
    }
    if (resources.size() > 0) {
        out.println("  Is sub class of: " + resourcesToString(resources));
    }
}
Also used : Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource) Value(org.openrdf.model.Value) HashSet(java.util.HashSet)

Aggregations

Value (org.openrdf.model.Value)46 Statement (org.openrdf.model.Statement)22 URI (org.openrdf.model.URI)22 Resource (org.openrdf.model.Resource)17 HashSet (java.util.HashSet)11 BindingSet (org.openrdf.query.BindingSet)10 TupleQueryResult (org.openrdf.query.TupleQueryResult)8 BNode (org.openrdf.model.BNode)6 Literal (org.openrdf.model.Literal)6 ExpressionQueryResult (edu.mit.simile.backstage.model.data.ExpressionQueryResult)5 ScriptableArrayBuilder (edu.mit.simile.backstage.util.ScriptableArrayBuilder)5 HashMap (java.util.HashMap)5 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)5 DefaultScriptableObject (edu.mit.simile.backstage.util.DefaultScriptableObject)4 ArrayList (java.util.ArrayList)4 Graph (org.openrdf.model.Graph)4 SailException (org.openrdf.sail.SailException)4 Map (java.util.Map)3 Set (java.util.Set)3 SparqlFieldQuery (org.apache.stanbol.entityhub.query.sparql.SparqlFieldQuery)3