http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/aggregation/AggregationPipelineQueryNode.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/aggregation/AggregationPipelineQueryNode.java b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/aggregation/AggregationPipelineQueryNode.java index 35525ad..6996fcd 100644 --- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/aggregation/AggregationPipelineQueryNode.java +++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/aggregation/AggregationPipelineQueryNode.java @@ -22,6 +22,7 @@ import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.CONTEXT; import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.DOCUMENT_VISIBILITY; import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.OBJECT; import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.OBJECT_HASH; +import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.OBJECT_LANGUAGE; import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.OBJECT_TYPE; import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.PREDICATE; import static org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.PREDICATE_HASH; @@ -42,9 +43,9 @@ import java.util.UUID; import java.util.concurrent.ConcurrentSkipListSet; import java.util.function.Function; +import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.resolver.RdfToRyaConversions; import org.apache.rya.mongodb.MongoDbRdfConstants; @@ -127,7 +128,7 @@ public class AggregationPipelineQueryNode extends ExternalSet { private static final Bson DEFAULT_METADATA = new Document("$literal", StatementMetadata.EMPTY_METADATA.toString()); - private static boolean isValidFieldName(String name) { + private static boolean isValidFieldName(final String name) { return !(name == null || name.contains(".") || name.contains("$") || name.equals("_id")); } @@ -144,13 +145,13 @@ public class AggregationPipelineQueryNode extends ExternalSet { private final Map<String, String> varToTripleType = new HashMap<>(); private final BiMap<String, String> varToOriginalName; - String valueField(String varName) { + String valueField(final String varName) { return varToTripleValue.get(varName); } - String hashField(String varName) { + String hashField(final String varName) { return varToTripleHash.get(varName); } - String typeField(String varName) { + String typeField(final String varName) { return varToTripleType.get(varName); } @@ -158,18 +159,18 @@ public class AggregationPipelineQueryNode extends ExternalSet { return varToTripleValue.keySet(); } - private String replace(String original) { + private String replace(final String original) { if (varToOriginalName.containsValue(original)) { return varToOriginalName.inverse().get(original); } else { - String replacement = "field-" + UUID.randomUUID(); + final String replacement = "field-" + UUID.randomUUID(); varToOriginalName.put(replacement, original); return replacement; } } - private String sanitize(String name) { + private String sanitize(final String name) { if (varToOriginalName.containsValue(name)) { return varToOriginalName.inverse().get(name); } @@ -179,26 +180,27 @@ public class AggregationPipelineQueryNode extends ExternalSet { return name; } - StatementVarMapping(StatementPattern sp, BiMap<String, String> varToOriginalName) { + StatementVarMapping(final StatementPattern sp, final BiMap<String, String> varToOriginalName) { this.varToOriginalName = varToOriginalName; if (sp.getSubjectVar() != null && !sp.getSubjectVar().hasValue()) { - String name = sanitize(sp.getSubjectVar().getName()); + final String name = sanitize(sp.getSubjectVar().getName()); varToTripleValue.put(name, SUBJECT); varToTripleHash.put(name, SUBJECT_HASH); } if (sp.getPredicateVar() != null && !sp.getPredicateVar().hasValue()) { - String name = sanitize(sp.getPredicateVar().getName()); + final String name = sanitize(sp.getPredicateVar().getName()); varToTripleValue.put(name, PREDICATE); varToTripleHash.put(name, PREDICATE_HASH); } if (sp.getObjectVar() != null && !sp.getObjectVar().hasValue()) { - String name = sanitize(sp.getObjectVar().getName()); + final String name = sanitize(sp.getObjectVar().getName()); varToTripleValue.put(name, OBJECT); varToTripleHash.put(name, OBJECT_HASH); varToTripleType.put(name, OBJECT_TYPE); + varToTripleType.put(name, OBJECT_LANGUAGE); } if (sp.getContextVar() != null && !sp.getContextVar().hasValue()) { - String name = sanitize(sp.getContextVar().getName()); + final String name = sanitize(sp.getContextVar().getName()); varToTripleValue.put(name, CONTEXT); } } @@ -207,12 +209,12 @@ public class AggregationPipelineQueryNode extends ExternalSet { return getProjectExpression(new LinkedList<>(), str -> "$" + str); } - Bson getProjectExpression(Iterable<String> alsoInclude, - Function<String, String> getFieldExpr) { - Document values = new Document(); - Document hashes = new Document(); - Document types = new Document(); - for (String varName : varNames()) { + Bson getProjectExpression(final Iterable<String> alsoInclude, + final Function<String, String> getFieldExpr) { + final Document values = new Document(); + final Document hashes = new Document(); + final Document types = new Document(); + for (final String varName : varNames()) { values.append(varName, getFieldExpr.apply(valueField(varName))); if (varToTripleHash.containsKey(varName)) { hashes.append(varName, getFieldExpr.apply(hashField(varName))); @@ -221,12 +223,12 @@ public class AggregationPipelineQueryNode extends ExternalSet { types.append(varName, getFieldExpr.apply(typeField(varName))); } } - for (String varName : alsoInclude) { + for (final String varName : alsoInclude) { values.append(varName, 1); hashes.append(varName, 1); types.append(varName, 1); } - List<Bson> fields = new LinkedList<>(); + final List<Bson> fields = new LinkedList<>(); fields.add(Projections.excludeId()); fields.add(Projections.computed(VALUES, values)); fields.add(Projections.computed(HASHES, hashes)); @@ -251,7 +253,7 @@ public class AggregationPipelineQueryNode extends ExternalSet { * "x" followed by "y". * @return The argument of a "$match" query */ - private static BasicDBObject getMatchExpression(StatementPattern sp, String ... path) { + private static BasicDBObject getMatchExpression(final StatementPattern sp, final String ... path) { final Var subjVar = sp.getSubjectVar(); final Var predVar = sp.getPredicateVar(); final Var objVar = sp.getObjectVar(); @@ -272,34 +274,34 @@ public class AggregationPipelineQueryNode extends ExternalSet { if (contextVar != null && contextVar.getValue() instanceof IRI) { c = RdfToRyaConversions.convertIRI((IRI) contextVar.getValue()); } - RyaStatement rs = new RyaStatement(s, p, o, c); - DBObject obj = strategy.getQuery(rs); + final RyaStatement rs = new RyaStatement(s, p, o, c); + final DBObject obj = strategy.getQuery(rs); // Add path prefix, if given if (path.length > 0) { - StringBuilder sb = new StringBuilder(); - for (String str : path) { + final StringBuilder sb = new StringBuilder(); + for (final String str : path) { sb.append(str).append("."); } - String prefix = sb.toString(); - Set<String> originalKeys = new HashSet<>(obj.keySet()); + final String prefix = sb.toString(); + final Set<String> originalKeys = new HashSet<>(obj.keySet()); originalKeys.forEach(key -> { - Object value = obj.removeField(key); + final Object value = obj.removeField(key); obj.put(prefix + key, value); }); } return (BasicDBObject) obj; } - private static String valueFieldExpr(String varName) { + private static String valueFieldExpr(final String varName) { return "$" + VALUES + "." + varName; } - private static String hashFieldExpr(String varName) { + private static String hashFieldExpr(final String varName) { return "$" + HASHES + "." + varName; } - private static String typeFieldExpr(String varName) { + private static String typeFieldExpr(final String varName) { return "$" + TYPES + "." + varName; } - private static String joinFieldExpr(String triplePart) { + private static String joinFieldExpr(final String triplePart) { return "$" + JOINED_TRIPLE + "." + triplePart; } @@ -307,7 +309,7 @@ public class AggregationPipelineQueryNode extends ExternalSet { * Get an object representing the value field of some value expression, or * return null if the expression isn't supported. */ - private Object valueFieldExpr(ValueExpr expr) { + private Object valueFieldExpr(final ValueExpr expr) { if (expr instanceof Var) { return valueFieldExpr(((Var) expr).getName()); } @@ -325,12 +327,12 @@ public class AggregationPipelineQueryNode extends ExternalSet { private final Set<String> bindingNames; private final BiMap<String, String> varToOriginalName; - private String replace(String original) { + private String replace(final String original) { if (varToOriginalName.containsValue(original)) { return varToOriginalName.inverse().get(original); } else { - String replacement = "field-" + UUID.randomUUID(); + final String replacement = "field-" + UUID.randomUUID(); varToOriginalName.put(replacement, original); return replacement; } @@ -341,11 +343,11 @@ public class AggregationPipelineQueryNode extends ExternalSet { * @param collection The collection of triples to query. * @param baseSP The leaf node in the query tree. */ - public AggregationPipelineQueryNode(MongoCollection<Document> collection, StatementPattern baseSP) { + public AggregationPipelineQueryNode(final MongoCollection<Document> collection, final StatementPattern baseSP) { this.collection = Preconditions.checkNotNull(collection); Preconditions.checkNotNull(baseSP); this.varToOriginalName = HashBiMap.create(); - StatementVarMapping mapping = new StatementVarMapping(baseSP, varToOriginalName); + final StatementVarMapping mapping = new StatementVarMapping(baseSP, varToOriginalName); this.assuredBindingNames = new HashSet<>(mapping.varNames()); this.bindingNames = new HashSet<>(mapping.varNames()); this.pipeline = new LinkedList<>(); @@ -353,9 +355,9 @@ public class AggregationPipelineQueryNode extends ExternalSet { this.pipeline.add(Aggregates.project(mapping.getProjectExpression())); } - AggregationPipelineQueryNode(MongoCollection<Document> collection, - List<Bson> pipeline, Set<String> assuredBindingNames, - Set<String> bindingNames, BiMap<String, String> varToOriginalName) { + AggregationPipelineQueryNode(final MongoCollection<Document> collection, + final List<Bson> pipeline, final Set<String> assuredBindingNames, + final Set<String> bindingNames, final BiMap<String, String> varToOriginalName) { this.collection = Preconditions.checkNotNull(collection); this.pipeline = Preconditions.checkNotNull(pipeline); this.assuredBindingNames = Preconditions.checkNotNull(assuredBindingNames); @@ -364,12 +366,12 @@ public class AggregationPipelineQueryNode extends ExternalSet { } @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if (this == o) { return true; } if (o instanceof AggregationPipelineQueryNode) { - AggregationPipelineQueryNode other = (AggregationPipelineQueryNode) o; + final AggregationPipelineQueryNode other = (AggregationPipelineQueryNode) o; if (this.collection.equals(other.collection) && this.assuredBindingNames.equals(other.assuredBindingNames) && this.bindingNames.equals(other.bindingNames) @@ -379,8 +381,8 @@ public class AggregationPipelineQueryNode extends ExternalSet { // have well-behaved equals methods, so check for equivalent // string representations. for (int i = 0; i < this.pipeline.size(); i++) { - Bson doc1 = this.pipeline.get(i); - Bson doc2 = other.pipeline.get(i); + final Bson doc1 = this.pipeline.get(i); + final Bson doc2 = other.pipeline.get(i); if (!doc1.toString().equals(doc2.toString())) { return false; } @@ -398,15 +400,15 @@ public class AggregationPipelineQueryNode extends ExternalSet { } @Override - public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BindingSet bindings) + public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindings) throws QueryEvaluationException { return new PipelineResultIteration(collection.aggregate(pipeline), varToOriginalName, bindings); } @Override public Set<String> getAssuredBindingNames() { - Set<String> names = new HashSet<>(); - for (String name : assuredBindingNames) { + final Set<String> names = new HashSet<>(); + for (final String name : assuredBindingNames) { names.add(varToOriginalName.getOrDefault(name, name)); } return names; @@ -414,8 +416,8 @@ public class AggregationPipelineQueryNode extends ExternalSet { @Override public Set<String> getBindingNames() { - Set<String> names = new HashSet<>(); - for (String name : bindingNames) { + final Set<String> names = new HashSet<>(); + for (final String name : bindingNames) { names.add(varToOriginalName.getOrDefault(name, name)); } return names; @@ -433,19 +435,19 @@ public class AggregationPipelineQueryNode extends ExternalSet { @Override public String getSignature() { super.getSignature(); - Set<String> assured = getAssuredBindingNames(); - Set<String> any = getBindingNames(); - StringBuilder sb = new StringBuilder("AggregationPipelineQueryNode (binds: "); + final Set<String> assured = getAssuredBindingNames(); + final Set<String> any = getBindingNames(); + final StringBuilder sb = new StringBuilder("AggregationPipelineQueryNode (binds: "); sb.append(String.join(", ", assured)); if (any.size() > assured.size()) { - Set<String> optionalBindingNames = any; + final Set<String> optionalBindingNames = any; optionalBindingNames.removeAll(assured); sb.append(" [") .append(String.join(", ", optionalBindingNames)) .append("]"); } sb.append(")\n"); - for (Bson doc : pipeline) { + for (final Bson doc : pipeline) { sb.append(doc.toString()).append("\n"); } return sb.toString(); @@ -468,15 +470,15 @@ public class AggregationPipelineQueryNode extends ExternalSet { * @param sp The statement pattern to join with * @return true if the join was successfully added to the pipeline. */ - public boolean joinWith(StatementPattern sp) { + public boolean joinWith(final StatementPattern sp) { Preconditions.checkNotNull(sp); // 1. Determine shared variables and new variables - StatementVarMapping spMap = new StatementVarMapping(sp, varToOriginalName); - NavigableSet<String> sharedVars = new ConcurrentSkipListSet<>(spMap.varNames()); + final StatementVarMapping spMap = new StatementVarMapping(sp, varToOriginalName); + final NavigableSet<String> sharedVars = new ConcurrentSkipListSet<>(spMap.varNames()); sharedVars.retainAll(assuredBindingNames); // 2. Join on one shared variable - String joinKey = sharedVars.pollFirst(); - String collectionName = collection.getNamespace().getCollectionName(); + final String joinKey = sharedVars.pollFirst(); + final String collectionName = collection.getNamespace().getCollectionName(); Bson join; if (joinKey == null) { return false; @@ -494,16 +496,16 @@ public class AggregationPipelineQueryNode extends ExternalSet { // 4. (Optional) If there are any shared variables that weren't used as // the join key, project all existing fields plus a new field that // tests the equality of those shared variables. - BasicDBObject matchOpts = getMatchExpression(sp, JOINED_TRIPLE); + final BasicDBObject matchOpts = getMatchExpression(sp, JOINED_TRIPLE); if (!sharedVars.isEmpty()) { - List<Bson> eqTests = new LinkedList<>(); - for (String varName : sharedVars) { - String oldField = valueFieldExpr(varName); - String newField = joinFieldExpr(spMap.valueField(varName)); - Bson eqTest = new Document("$eq", Arrays.asList(oldField, newField)); + final List<Bson> eqTests = new LinkedList<>(); + for (final String varName : sharedVars) { + final String oldField = valueFieldExpr(varName); + final String newField = joinFieldExpr(spMap.valueField(varName)); + final Bson eqTest = new Document("$eq", Arrays.asList(oldField, newField)); eqTests.add(eqTest); } - Bson eqProjectOpts = Projections.fields( + final Bson eqProjectOpts = Projections.fields( Projections.computed(FIELDS_MATCH, Filters.and(eqTests)), Projections.include(JOINED_TRIPLE, VALUES, HASHES, TYPES, LEVEL, TIMESTAMP)); pipeline.add(Aggregates.project(eqProjectOpts)); @@ -516,7 +518,7 @@ public class AggregationPipelineQueryNode extends ExternalSet { // 6. Project the results to include variables from the new SP (with // appropriate renaming) and variables referenced only in the base // pipeline (with previous names). - Bson finalProjectOpts = new StatementVarMapping(sp, varToOriginalName) + final Bson finalProjectOpts = new StatementVarMapping(sp, varToOriginalName) .getProjectExpression(assuredBindingNames, str -> joinFieldExpr(str)); assuredBindingNames.addAll(spMap.varNames()); @@ -537,23 +539,23 @@ public class AggregationPipelineQueryNode extends ExternalSet { * at this stage of the query into a set of variables. * @return true if the projection(s) were added to the pipeline. */ - public boolean project(Iterable<ProjectionElemList> projections) { + public boolean project(final Iterable<ProjectionElemList> projections) { if (projections == null || !projections.iterator().hasNext()) { return false; } - List<Bson> projectOpts = new LinkedList<>(); - Set<String> bindingNamesUnion = new HashSet<>(); + final List<Bson> projectOpts = new LinkedList<>(); + final Set<String> bindingNamesUnion = new HashSet<>(); Set<String> bindingNamesIntersection = null; - for (ProjectionElemList projection : projections) { + for (final ProjectionElemList projection : projections) { if (projection.getElements().isEmpty()) { // Empty projections are unsupported -- fail when seen return false; } - Document valueDoc = new Document(); - Document hashDoc = new Document(); - Document typeDoc = new Document(); - Set<String> projectionBindingNames = new HashSet<>(); - for (ProjectionElem elem : projection.getElements()) { + final Document valueDoc = new Document(); + final Document hashDoc = new Document(); + final Document typeDoc = new Document(); + final Set<String> projectionBindingNames = new HashSet<>(); + for (final ProjectionElem elem : projection.getElements()) { String to = elem.getTargetName(); // If the 'to' name is invalid, replace it internally if (!isValidFieldName(to)) { @@ -594,8 +596,8 @@ public class AggregationPipelineQueryNode extends ExternalSet { pipeline.add(Aggregates.project(projectOpts.get(0))); } else { - String listKey = "PROJECTIONS"; - Bson projectIndividual = Projections.fields( + final String listKey = "PROJECTIONS"; + final Bson projectIndividual = Projections.fields( Projections.computed(VALUES, "$" + listKey + "." + VALUES), Projections.computed(HASHES, "$" + listKey + "." + HASHES), Projections.computed(TYPES, "$" + listKey + "." + TYPES), @@ -625,17 +627,17 @@ public class AggregationPipelineQueryNode extends ExternalSet { * @return True if the extension was successfully converted into a pipeline * step, false otherwise. */ - public boolean extend(Iterable<ExtensionElem> extensionElements) { - List<Bson> valueFields = new LinkedList<>(); - List<Bson> hashFields = new LinkedList<>(); - List<Bson> typeFields = new LinkedList<>(); - for (String varName : bindingNames) { + public boolean extend(final Iterable<ExtensionElem> extensionElements) { + final List<Bson> valueFields = new LinkedList<>(); + final List<Bson> hashFields = new LinkedList<>(); + final List<Bson> typeFields = new LinkedList<>(); + for (final String varName : bindingNames) { valueFields.add(Projections.include(varName)); hashFields.add(Projections.include(varName)); typeFields.add(Projections.include(varName)); } - Set<String> newVarNames = new HashSet<>(); - for (ExtensionElem elem : extensionElements) { + final Set<String> newVarNames = new HashSet<>(); + for (final ExtensionElem elem : extensionElements) { String name = elem.getName(); if (!isValidFieldName(name)) { // If the field name is invalid, replace it internally @@ -643,18 +645,18 @@ public class AggregationPipelineQueryNode extends ExternalSet { } // We can only handle certain kinds of value expressions; return // failure for any others. - ValueExpr expr = elem.getExpr(); + final ValueExpr expr = elem.getExpr(); final Object valueField; final Object hashField; final Object typeField; if (expr instanceof Var) { - String varName = ((Var) expr).getName(); + final String varName = ((Var) expr).getName(); valueField = "$" + varName; hashField = "$" + varName; typeField = "$" + varName; } else if (expr instanceof ValueConstant) { - Value val = ((ValueConstant) expr).getValue(); + final Value val = ((ValueConstant) expr).getValue(); valueField = new Document("$literal", val.stringValue()); hashField = new Document("$literal", SimpleMongoDBStorageStrategy.hash(val.stringValue())); if (val instanceof Literal) { @@ -677,7 +679,7 @@ public class AggregationPipelineQueryNode extends ExternalSet { } assuredBindingNames.addAll(newVarNames); bindingNames.addAll(newVarNames); - Bson projectOpts = Projections.fields( + final Bson projectOpts = Projections.fields( Projections.computed(VALUES, Projections.fields(valueFields)), Projections.computed(HASHES, Projections.fields(hashFields)), Projections.computed(TYPES, Projections.fields(typeFields)), @@ -698,12 +700,12 @@ public class AggregationPipelineQueryNode extends ExternalSet { * @return True if the filter was successfully converted into a pipeline * step, false otherwise. */ - public boolean filter(ValueExpr condition) { + public boolean filter(final ValueExpr condition) { if (condition instanceof Compare) { - Compare compare = (Compare) condition; - Compare.CompareOp operator = compare.getOperator(); - Object leftArg = valueFieldExpr(compare.getLeftArg()); - Object rightArg = valueFieldExpr(compare.getRightArg()); + final Compare compare = (Compare) condition; + final Compare.CompareOp operator = compare.getOperator(); + final Object leftArg = valueFieldExpr(compare.getLeftArg()); + final Object rightArg = valueFieldExpr(compare.getRightArg()); if (leftArg == null || rightArg == null) { // unsupported value expression, can't convert filter return false; @@ -732,7 +734,7 @@ public class AggregationPipelineQueryNode extends ExternalSet { // unrecognized comparison operator, can't convert filter return false; } - Document compareDoc = new Document(opFunc, Arrays.asList(leftArg, rightArg)); + final Document compareDoc = new Document(opFunc, Arrays.asList(leftArg, rightArg)); pipeline.add(Aggregates.project(Projections.fields( Projections.computed("FILTER", compareDoc), Projections.include(VALUES, HASHES, TYPES, LEVEL, TIMESTAMP)))); @@ -749,12 +751,12 @@ public class AggregationPipelineQueryNode extends ExternalSet { * @return True if the distinct operation was successfully appended. */ public boolean distinct() { - List<String> key = new LinkedList<>(); - for (String varName : bindingNames) { + final List<String> key = new LinkedList<>(); + for (final String varName : bindingNames) { key.add(hashFieldExpr(varName)); } - List<BsonField> reduceOps = new LinkedList<>(); - for (String field : FIELDS) { + final List<BsonField> reduceOps = new LinkedList<>(); + for (final String field : FIELDS) { reduceOps.add(new BsonField(field, new Document("$first", "$" + field))); } pipeline.add(Aggregates.group(new Document("$concat", key), reduceOps)); @@ -774,7 +776,7 @@ public class AggregationPipelineQueryNode extends ExternalSet { * query if all of the triples involved in producing that solution have a * lower derivation depth than this. If zero, does nothing. */ - public void requireSourceDerivationDepth(int requiredLevel) { + public void requireSourceDerivationDepth(final int requiredLevel) { if (requiredLevel > 0) { pipeline.add(Aggregates.match(new Document(LEVEL, new Document("$gte", requiredLevel)))); @@ -791,7 +793,7 @@ public class AggregationPipelineQueryNode extends ExternalSet { * all of the triples involved in producing that solution have an earlier * timestamp than this. */ - public void requireSourceTimestamp(long t) { + public void requireSourceTimestamp(final long t) { pipeline.add(Aggregates.match(new Document(TIMESTAMP, new Document("$gte", t)))); } @@ -810,7 +812,7 @@ public class AggregationPipelineQueryNode extends ExternalSet { * pipeline do not have variable names allowing them to be interpreted as * triples (i.e. "subject", "predicate", and "object"). */ - public List<Bson> getTriplePipeline(long timestamp, boolean requireNew) { + public List<Bson> getTriplePipeline(final long timestamp, final boolean requireNew) { if (!assuredBindingNames.contains(SUBJECT) || !assuredBindingNames.contains(PREDICATE) || !assuredBindingNames.contains(OBJECT)) { @@ -820,8 +822,8 @@ public class AggregationPipelineQueryNode extends ExternalSet { + ", " + OBJECT + ">\nCurrent variable names: " + assuredBindingNames); } - List<Bson> triplePipeline = new LinkedList<>(pipeline); - List<Bson> fields = new LinkedList<>(); + final List<Bson> triplePipeline = new LinkedList<>(pipeline); + final List<Bson> fields = new LinkedList<>(); fields.add(Projections.computed(SUBJECT, valueFieldExpr(SUBJECT))); fields.add(Projections.computed(SUBJECT_HASH, hashFieldExpr(SUBJECT))); fields.add(Projections.computed(PREDICATE, valueFieldExpr(PREDICATE))); @@ -830,6 +832,7 @@ public class AggregationPipelineQueryNode extends ExternalSet { fields.add(Projections.computed(OBJECT_HASH, hashFieldExpr(OBJECT))); fields.add(Projections.computed(OBJECT_TYPE, ConditionalOperators.ifNull(typeFieldExpr(OBJECT), DEFAULT_TYPE))); + fields.add(Projections.computed(OBJECT_LANGUAGE, hashFieldExpr(OBJECT))); fields.add(Projections.computed(CONTEXT, DEFAULT_CONTEXT)); fields.add(Projections.computed(STATEMENT_METADATA, DEFAULT_METADATA)); fields.add(DEFAULT_DV); @@ -838,19 +841,19 @@ public class AggregationPipelineQueryNode extends ExternalSet { triplePipeline.add(Aggregates.project(Projections.fields(fields))); if (requireNew) { // Prune any triples that already exist in the data store - String collectionName = collection.getNamespace().getCollectionName(); - Bson includeAll = Projections.include(SUBJECT, SUBJECT_HASH, + final String collectionName = collection.getNamespace().getCollectionName(); + final Bson includeAll = Projections.include(SUBJECT, SUBJECT_HASH, PREDICATE, PREDICATE_HASH, OBJECT, OBJECT_HASH, - OBJECT_TYPE, CONTEXT, STATEMENT_METADATA, + OBJECT_TYPE, OBJECT_LANGUAGE, CONTEXT, STATEMENT_METADATA, DOCUMENT_VISIBILITY, TIMESTAMP, LEVEL); - List<Bson> eqTests = new LinkedList<>(); + final List<Bson> eqTests = new LinkedList<>(); eqTests.add(new Document("$eq", Arrays.asList("$$this." + PREDICATE_HASH, "$" + PREDICATE_HASH))); eqTests.add(new Document("$eq", Arrays.asList("$$this." + OBJECT_HASH, "$" + OBJECT_HASH))); - Bson redundantFilter = new Document("$filter", new Document("input", "$" + JOINED_TRIPLE) + final Bson redundantFilter = new Document("$filter", new Document("input", "$" + JOINED_TRIPLE) .append("as", "this").append("cond", new Document("$and", eqTests))); triplePipeline.add(Aggregates.lookup(collectionName, SUBJECT_HASH, SUBJECT_HASH, JOINED_TRIPLE)); - String numRedundant = "REDUNDANT"; + final String numRedundant = "REDUNDANT"; triplePipeline.add(Aggregates.project(Projections.fields(includeAll, Projections.computed(numRedundant, new Document("$size", redundantFilter))))); triplePipeline.add(Aggregates.match(Filters.eq(numRedundant, 0)));
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java index ec5c7a5..7d4911f 100644 --- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java +++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java @@ -28,11 +28,12 @@ import java.util.Map; import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; import org.apache.log4j.Logger; +import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; -import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.persist.query.RyaQuery; +import org.apache.rya.api.utils.LiteralLanguageUtils; import org.apache.rya.mongodb.document.visibility.DocumentVisibility; import org.apache.rya.mongodb.document.visibility.DocumentVisibilityAdapter; import org.apache.rya.mongodb.document.visibility.DocumentVisibilityAdapter.MalformedDocumentVisibilityException; @@ -57,6 +58,7 @@ public class SimpleMongoDBStorageStrategy implements MongoDBStorageStrategy<RyaS public static final String PREDICATE_HASH = "predicate_hash"; public static final String OBJECT = "object"; public static final String OBJECT_HASH = "object_hash"; + public static final String OBJECT_LANGUAGE = "object_language"; public static final String SUBJECT = "subject"; public static final String SUBJECT_HASH = "subject_hash"; public static final String TIMESTAMP = "insertTimestamp"; @@ -68,7 +70,7 @@ public class SimpleMongoDBStorageStrategy implements MongoDBStorageStrategy<RyaS * @param value A value to be stored or accessed (e.g. a IRI or literal). * @return the hash associated with that value in MongoDB. */ - public static String hash(String value) { + public static String hash(final String value) { return DigestUtils.sha256Hex(value); } @@ -81,13 +83,16 @@ public class SimpleMongoDBStorageStrategy implements MongoDBStorageStrategy<RyaS doc.put(PREDICATE_HASH, 1); doc.put(OBJECT_HASH, 1); doc.put(OBJECT_TYPE, 1); + doc.put(OBJECT_LANGUAGE, 1); coll.createIndex(doc); doc = new BasicDBObject(PREDICATE_HASH, 1); doc.put(OBJECT_HASH, 1); doc.put(OBJECT_TYPE, 1); + doc.put(OBJECT_LANGUAGE, 1); coll.createIndex(doc); doc = new BasicDBObject(OBJECT_HASH, 1); doc.put(OBJECT_TYPE, 1); + doc.put(OBJECT_LANGUAGE, 1); doc.put(SUBJECT_HASH, 1); coll.createIndex(doc); } @@ -105,6 +110,7 @@ public class SimpleMongoDBStorageStrategy implements MongoDBStorageStrategy<RyaS if (object != null){ query.append(OBJECT_HASH, hash(object.getData())); query.append(OBJECT_TYPE, object.getDataType().toString()); + query.append(OBJECT_LANGUAGE, object.getLanguage()); } if (predicate != null){ query.append(PREDICATE_HASH, hash(predicate.getData())); @@ -121,6 +127,7 @@ public class SimpleMongoDBStorageStrategy implements MongoDBStorageStrategy<RyaS final String subject = (String) result.get(SUBJECT); final String object = (String) result.get(OBJECT); final String objectType = (String) result.get(OBJECT_TYPE); + final String objectLanguage = (String) result.get(OBJECT_LANGUAGE); final String predicate = (String) result.get(PREDICATE); final String context = (String) result.get(CONTEXT); DocumentVisibility documentVisibility = null; @@ -132,10 +139,12 @@ public class SimpleMongoDBStorageStrategy implements MongoDBStorageStrategy<RyaS final Long timestamp = (Long) result.get(TIMESTAMP); final String statementMetadata = (String) result.get(STATEMENT_METADATA); RyaType objectRya = null; + final String validatedLanguage = LiteralLanguageUtils.validateLanguage(objectLanguage, factory.createIRI(objectType)); if (objectType.equalsIgnoreCase(ANYURI.stringValue())){ objectRya = new RyaIRI(object); - } - else { + } else if (validatedLanguage != null) { + objectRya = new RyaType(factory.createIRI(objectType), object, validatedLanguage); + } else { objectRya = new RyaType(factory.createIRI(objectType), object); } @@ -173,8 +182,9 @@ public class SimpleMongoDBStorageStrategy implements MongoDBStorageStrategy<RyaS if (statement.getContext() != null){ context = statement.getContext().getData(); } + final String validatedLanguage = LiteralLanguageUtils.validateLanguage(statement.getObject().getLanguage(), statement.getObject().getDataType()); final String id = statement.getSubject().getData() + " " + - statement.getPredicate().getData() + " " + statement.getObject().getData() + " " + context; + statement.getPredicate().getData() + " " + statement.getObject().getData() + (validatedLanguage != null ? " " + validatedLanguage : "") + " " + context; byte[] bytes = id.getBytes(StandardCharsets.UTF_8); try { final MessageDigest digest = MessageDigest.getInstance("SHA-1"); @@ -194,6 +204,7 @@ public class SimpleMongoDBStorageStrategy implements MongoDBStorageStrategy<RyaS .append(OBJECT, statement.getObject().getData()) .append(OBJECT_HASH, hash(statement.getObject().getData())) .append(OBJECT_TYPE, statement.getObject().getDataType().toString()) + .append(OBJECT_LANGUAGE, statement.getObject().getLanguage()) .append(CONTEXT, context) .append(STATEMENT_METADATA, statement.getMetadata().toString()) .append(DOCUMENT_VISIBILITY, dvObject.get(DOCUMENT_VISIBILITY)) http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/SimpleMongoDBStorageStrategyTest.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/SimpleMongoDBStorageStrategyTest.java b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/SimpleMongoDBStorageStrategyTest.java index 576610c..a757ba3 100644 --- a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/SimpleMongoDBStorageStrategyTest.java +++ b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/SimpleMongoDBStorageStrategyTest.java @@ -24,14 +24,16 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.rya.api.domain.RyaIRI; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder; -import org.apache.rya.api.domain.RyaIRI; +import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy; import org.apache.rya.mongodb.document.util.DocumentVisibilityConversionException; import org.apache.rya.mongodb.document.util.DocumentVisibilityUtil; import org.apache.rya.mongodb.document.visibility.DocumentVisibility; +import org.eclipse.rdf4j.model.vocabulary.RDF; import org.junit.Test; import com.mongodb.BasicDBObject; @@ -47,11 +49,13 @@ public class SimpleMongoDBStorageStrategyTest { private static final DocumentVisibility DOCUMENT_VISIBILITY = new DocumentVisibility("A&B"); private static final RyaStatement testStatement; + private static final RyaStatement testStatement2; private static final DBObject testDBO; + private static final DBObject testDBO2; private final SimpleMongoDBStorageStrategy storageStrategy = new SimpleMongoDBStorageStrategy(); static { - final RyaStatementBuilder builder = new RyaStatementBuilder(); + RyaStatementBuilder builder = new RyaStatementBuilder(); builder.setPredicate(new RyaIRI(PREDICATE)); builder.setSubject(new RyaIRI(SUBJECT)); builder.setObject(new RyaIRI(OBJECT)); @@ -69,6 +73,7 @@ public class SimpleMongoDBStorageStrategyTest { testDBO.put(SimpleMongoDBStorageStrategy.OBJECT, OBJECT); testDBO.put(SimpleMongoDBStorageStrategy.OBJECT_HASH, DigestUtils.sha256Hex(OBJECT)); testDBO.put(SimpleMongoDBStorageStrategy.OBJECT_TYPE, ANYURI.stringValue()); + testDBO.put(SimpleMongoDBStorageStrategy.OBJECT_LANGUAGE, null); testDBO.put(SimpleMongoDBStorageStrategy.CONTEXT, CONTEXT); testDBO.put(SimpleMongoDBStorageStrategy.STATEMENT_METADATA, STATEMENT_METADATA); try { @@ -77,18 +82,51 @@ public class SimpleMongoDBStorageStrategyTest { e.printStackTrace(); } testDBO.put(SimpleMongoDBStorageStrategy.TIMESTAMP, null); + + + builder = new RyaStatementBuilder(); + builder.setPredicate(new RyaIRI(PREDICATE)); + builder.setSubject(new RyaIRI(SUBJECT)); + builder.setObject(new RyaType(RDF.LANGSTRING, OBJECT, "en-US")); + builder.setContext(new RyaIRI(CONTEXT)); + builder.setColumnVisibility(DOCUMENT_VISIBILITY.flatten()); + builder.setTimestamp(null); + testStatement2 = builder.build(); + + // Check language support + testDBO2 = new BasicDBObject(); + testDBO2.put(SimpleMongoDBStorageStrategy.ID, "580fb5d11f0b62fa735ac98b36bba1fc37ddc3fc"); + testDBO2.put(SimpleMongoDBStorageStrategy.SUBJECT, SUBJECT); + testDBO2.put(SimpleMongoDBStorageStrategy.SUBJECT_HASH, DigestUtils.sha256Hex(SUBJECT)); + testDBO2.put(SimpleMongoDBStorageStrategy.PREDICATE, PREDICATE); + testDBO2.put(SimpleMongoDBStorageStrategy.PREDICATE_HASH, DigestUtils.sha256Hex(PREDICATE)); + testDBO2.put(SimpleMongoDBStorageStrategy.OBJECT, OBJECT); + testDBO2.put(SimpleMongoDBStorageStrategy.OBJECT_HASH, DigestUtils.sha256Hex(OBJECT)); + testDBO2.put(SimpleMongoDBStorageStrategy.OBJECT_TYPE, RDF.LANGSTRING.stringValue()); + testDBO2.put(SimpleMongoDBStorageStrategy.OBJECT_LANGUAGE, "en-US"); + testDBO2.put(SimpleMongoDBStorageStrategy.CONTEXT, CONTEXT); + testDBO2.put(SimpleMongoDBStorageStrategy.STATEMENT_METADATA, STATEMENT_METADATA); + try { + testDBO2.put(SimpleMongoDBStorageStrategy.DOCUMENT_VISIBILITY, DocumentVisibilityUtil.toMultidimensionalArray(DOCUMENT_VISIBILITY)); + } catch (final DocumentVisibilityConversionException e) { + e.printStackTrace(); + } + testDBO2.put(SimpleMongoDBStorageStrategy.TIMESTAMP, null); } @Test public void testSerializeStatementToDBO() throws RyaDAOException, MongoException, IOException { - final DBObject dbo = storageStrategy.serialize(testStatement); + DBObject dbo = storageStrategy.serialize(testStatement); assertEquals(testDBO, dbo); + + dbo = storageStrategy.serialize(testStatement2); + assertEquals(testDBO2, dbo); } @Test public void testDeSerializeStatementToDBO() throws RyaDAOException, MongoException, IOException { - final RyaStatement statement = storageStrategy.deserializeDBObject(testDBO); + RyaStatement statement = storageStrategy.deserializeDBObject(testDBO); /* * Since RyaStatement creates a timestamp using JVM time if the timestamp is null, we want to re-null it * for this test. Timestamp is created at insert time by the Server, this test @@ -96,5 +134,14 @@ public class SimpleMongoDBStorageStrategyTest { */ statement.setTimestamp(null); assertEquals(testStatement, statement); + + statement = storageStrategy.deserializeDBObject(testDBO2); + /* + * Since RyaStatement creates a timestamp using JVM time if the timestamp is null, we want to re-null it + * for this test. Timestamp is created at insert time by the Server, this test + * can be found in the RyaDAO. + */ + statement.setTimestamp(null); + assertEquals(testStatement2, statement); } } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/pom.xml ---------------------------------------------------------------------- diff --git a/extras/indexing/pom.xml b/extras/indexing/pom.xml index 837d67a..329b980 100644 --- a/extras/indexing/pom.xml +++ b/extras/indexing/pom.xml @@ -133,6 +133,7 @@ <excludes> <!-- RDF data Files --> <exclude>**/*.ttl</exclude> + <exclude>**/src/test/resources/rdf_format_files/**</exclude> <!-- Services Files --> <exclude>**/resources/META-INF/services/**</exclude> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/main/java/org/apache/rya/indexing/StatementSerializer.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/StatementSerializer.java b/extras/indexing/src/main/java/org/apache/rya/indexing/StatementSerializer.java index 8ea44c5..db8dfac 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/StatementSerializer.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/StatementSerializer.java @@ -8,9 +8,9 @@ package org.apache.rya.indexing; * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -24,6 +24,7 @@ import java.util.Set; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.Validate; +import org.apache.rya.api.utils.LiteralLanguageUtils; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Literal; import org.eclipse.rdf4j.model.Resource; @@ -42,34 +43,34 @@ public class StatementSerializer { /** * Read a {@link Statement} from a {@link String} - * + * * @param in * the {@link String} to parse * @return a {@link Statement} */ - public static Statement readStatement(String in) throws IOException { - String[] parts = in.split(SEP); - + public static Statement readStatement(final String in) throws IOException { + final String[] parts = in.split(SEP); + if (parts.length != 4) { throw new IOException("Not a valid statement: " + in); } - - String contextString = parts[0]; - String subjectString = parts[1]; - String predicateString = parts[2]; - String objectString = parts[3]; + + final String contextString = parts[0]; + final String subjectString = parts[1]; + final String predicateString = parts[2]; + final String objectString = parts[3]; return readStatement(subjectString, predicateString, objectString, contextString); } - public static Statement readStatement(String subjectString, String predicateString, String objectString) { + public static Statement readStatement(final String subjectString, final String predicateString, final String objectString) { return readStatement(subjectString, predicateString, objectString, ""); } - public static Statement readStatement(String subjectString, String predicateString, String objectString, String contextString) { - Resource subject = createResource(subjectString); - IRI predicate = VF.createIRI(predicateString); + public static Statement readStatement(final String subjectString, final String predicateString, final String objectString, final String contextString) { + final Resource subject = createResource(subjectString); + final IRI predicate = VF.createIRI(predicateString); - boolean isObjectLiteral = objectString.startsWith("\""); + final boolean isObjectLiteral = objectString.startsWith("\""); Value object = null; if (isObjectLiteral) { @@ -81,12 +82,12 @@ public class StatementSerializer { if (contextString == null || contextString.isEmpty()) { return VF.createStatement(subject, predicate, object); } else { - Resource context = VF.createIRI(contextString); + final Resource context = VF.createIRI(contextString); return VF.createStatement(subject, predicate, object, context); } } - private static Resource createResource(String str) { + private static Resource createResource(final String str) { if (str.startsWith("_")) { return VF.createBNode(str.substring(2)); } @@ -94,30 +95,30 @@ public class StatementSerializer { } - private static Literal parseLiteral(String fullLiteralString) { + private static Literal parseLiteral(final String fullLiteralString) { Validate.notNull(fullLiteralString); Validate.isTrue(fullLiteralString.length() > 1); if (fullLiteralString.endsWith("\"")) { - String fullLiteralWithoutQuotes = fullLiteralString.substring(1, fullLiteralString.length() - 1); + final String fullLiteralWithoutQuotes = fullLiteralString.substring(1, fullLiteralString.length() - 1); return VF.createLiteral(fullLiteralWithoutQuotes); } else { // find the closing quote - int labelEnd = fullLiteralString.lastIndexOf("\""); + final int labelEnd = fullLiteralString.lastIndexOf("\""); - String label = fullLiteralString.substring(1, labelEnd); + final String label = fullLiteralString.substring(1, labelEnd); - String data = fullLiteralString.substring(labelEnd + 1); + final String data = fullLiteralString.substring(labelEnd + 1); - if (data.startsWith("@")) { + if (data.startsWith(LiteralLanguageUtils.LANGUAGE_DELIMITER)) { // the data is "language" - String lang = data.substring(1); + final String lang = data.substring(1); return VF.createLiteral(label, lang); } else if (data.startsWith("^^<")) { // the data is a "datatype" - String datatype = data.substring(3, data.length() - 1); - IRI datatypeUri = VF.createIRI(datatype); + final String datatype = data.substring(3, data.length() - 1); + final IRI datatypeUri = VF.createIRI(datatype); return VF.createLiteral(label, datatypeUri); } } @@ -125,26 +126,26 @@ public class StatementSerializer { } - public static String writeSubject(Statement statement) { + public static String writeSubject(final Statement statement) { return statement.getSubject().toString(); } - public static String writeObject(Statement statement) { + public static String writeObject(final Statement statement) { return statement.getObject().toString(); } - public static String writePredicate(Statement statement) { + public static String writePredicate(final Statement statement) { return statement.getPredicate().toString(); } - public static String writeSubjectPredicate(Statement statement) { + public static String writeSubjectPredicate(final Statement statement) { Validate.notNull(statement); Validate.notNull(statement.getSubject()); Validate.notNull(statement.getPredicate()); return statement.getSubject().toString() + SEP + statement.getPredicate().toString(); } - public static String writeContext(Statement statement) { + public static String writeContext(final Statement statement) { if (statement.getContext() == null) { return ""; } @@ -153,16 +154,16 @@ public class StatementSerializer { /** * Write a {@link Statement} to a {@link String} - * + * * @param statement * the {@link Statement} to write * @return a {@link String} representation of the statement */ - public static String writeStatement(Statement statement) { - Resource subject = statement.getSubject(); - Resource context = statement.getContext(); - IRI predicate = statement.getPredicate(); - Value object = statement.getObject(); + public static String writeStatement(final Statement statement) { + final Resource subject = statement.getSubject(); + final Resource context = statement.getContext(); + final IRI predicate = statement.getPredicate(); + final Value object = statement.getObject(); Validate.notNull(subject); Validate.notNull(predicate); @@ -180,7 +181,7 @@ public class StatementSerializer { /** * Creates a Regular Expression to match serialized statements meeting these constraints. A <code>null</code> or empty parameters imply * no constraint. A <code>null</code> return value implies no constraints. - * + * * @param context * context constraint * @param subject @@ -190,22 +191,22 @@ public class StatementSerializer { * @return a regular expression that can be used to match serialized statements. A <code>null</code> return value implies no * constraints. */ - public static String createStatementRegex(StatementConstraints contraints) { - Resource context = contraints.getContext(); - Resource subject = contraints.getSubject(); - Set<IRI> predicates = contraints.getPredicates(); + public static String createStatementRegex(final StatementConstraints contraints) { + final Resource context = contraints.getContext(); + final Resource subject = contraints.getSubject(); + final Set<IRI> predicates = contraints.getPredicates(); if (context == null && subject == null && (predicates == null || predicates.isEmpty())) { return null; } // match on anything but a separator - String anyReg = "[^" + SEP + "]*"; + final String anyReg = "[^" + SEP + "]*"; // if context is empty, match on any context - String contextReg = (context == null) ? anyReg : context.stringValue(); + final String contextReg = (context == null) ? anyReg : context.stringValue(); // if subject is empty, match on any subject - String subjectReg = (subject == null) ? anyReg : subject.stringValue(); + final String subjectReg = (subject == null) ? anyReg : subject.stringValue(); // if the predicates are empty, match on any predicate. Otherwise, "or" the predicates. String predicateReg = ""; http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/java/org/apache/rya/helper/TestFile.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/helper/TestFile.java b/extras/indexing/src/test/java/org/apache/rya/helper/TestFile.java new file mode 100644 index 0000000..3aee23c --- /dev/null +++ b/extras/indexing/src/test/java/org/apache/rya/helper/TestFile.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rya.helper; + +import static java.util.Objects.requireNonNull; + +/** + * Holds test file information. + */ +public class TestFile { + private final String path; + private final int expectedCount; + + /** + * Creates a new instance of {@link TestFile}. + * @param path the path of the file. (not {@code null}) + * @param expectedCount the number of expected triples it holds. + */ + public TestFile(final String path, final int expectedCount) { + this.path = requireNonNull(path); + this.expectedCount = expectedCount; + } + + /** + * @return the path of the file. + */ + public String getPath() { + return path; + } + + /** + * @return the number of expected triples it holds. + */ + public int getExpectedCount() { + return expectedCount; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/java/org/apache/rya/helper/TestFileUtils.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/helper/TestFileUtils.java b/extras/indexing/src/test/java/org/apache/rya/helper/TestFileUtils.java new file mode 100644 index 0000000..19dafe8 --- /dev/null +++ b/extras/indexing/src/test/java/org/apache/rya/helper/TestFileUtils.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rya.helper; + +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import com.google.common.collect.ImmutableSet; + +/** + * Holds constants relating to the RDF test files that will be used. + */ +public final class TestFileUtils { + public static final String RDF_FILE_DIR = "/rdf_format_files/"; + + /** + * All the test files that are found in + * "src/test/resources/rdf_format_files/" with their respective triple + * counts. + */ + public static final Set<TestFile> TEST_FILES = ImmutableSet.of( + new TestFile(RDF_FILE_DIR + "ntriples_data.nt", 3), + new TestFile(RDF_FILE_DIR + "n3_data.n3", 12), + new TestFile(RDF_FILE_DIR + "rdfxml_data.owl", 2), + new TestFile(RDF_FILE_DIR + "turtle_data.ttl", 7), + new TestFile(RDF_FILE_DIR + "trig_data.trig", 5), + new TestFile(RDF_FILE_DIR + "trix_data.trix", 3), + new TestFile(RDF_FILE_DIR + "nquads_data.nq", 2), + new TestFile(RDF_FILE_DIR + "jsonld_data.jsonld", 3), + new TestFile(RDF_FILE_DIR + "rdfjson_data.rj", 1), + new TestFile(RDF_FILE_DIR + "binary_data.brf", 4) + ); + + /** + * Constant that holds the total number of triples from all the test files + * held in {@link #TEST_FILES}. + */ + public static final int TOTAL_TRIPLES = + TEST_FILES.stream().map(TestFile::getExpectedCount).collect(Collectors.summingInt(Integer::intValue)); + + /** + * Convenience map to get the triple count from the test file path held in + * {@link #TEST_FILES}. + */ + public static final Map<String, Integer> FILE_TO_COUNT_MAP = + TEST_FILES.stream().collect(Collectors.toMap(TestFile::getPath, TestFile::getExpectedCount)); + + /** + * Private constructor to prevent instantiation. + */ + private TestFileUtils() { + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/java/org/apache/rya/sail/config/AccumuloRyaSailFactoryLoadFilesIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/sail/config/AccumuloRyaSailFactoryLoadFilesIT.java b/extras/indexing/src/test/java/org/apache/rya/sail/config/AccumuloRyaSailFactoryLoadFilesIT.java new file mode 100644 index 0000000..a75b8ba --- /dev/null +++ b/extras/indexing/src/test/java/org/apache/rya/sail/config/AccumuloRyaSailFactoryLoadFilesIT.java @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rya.sail.config; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.log4j.Logger; +import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.apache.rya.api.RdfCloudTripleStoreConfiguration; +import org.apache.rya.api.RdfCloudTripleStoreConstants; +import org.apache.rya.api.client.accumulo.AccumuloConnectionDetails; +import org.apache.rya.api.client.accumulo.AccumuloRyaClientFactory; +import org.apache.rya.helper.TestFile; +import org.apache.rya.helper.TestFileUtils; +import org.apache.rya.indexing.mongo.MongoPcjIntegrationTest.CountingResultHandler; +import org.apache.rya.rdftriplestore.RyaSailRepository; +import org.apache.rya.rdftriplestore.utils.RdfFormatUtils; +import org.apache.rya.test.accumulo.AccumuloITBase; +import org.eclipse.rdf4j.query.MalformedQueryException; +import org.eclipse.rdf4j.query.QueryEvaluationException; +import org.eclipse.rdf4j.query.QueryLanguage; +import org.eclipse.rdf4j.query.TupleQuery; +import org.eclipse.rdf4j.query.TupleQueryResultHandlerException; +import org.eclipse.rdf4j.query.Update; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryException; +import org.eclipse.rdf4j.repository.sail.SailRepository; +import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection; +import org.eclipse.rdf4j.rio.RDFFormat; +import org.eclipse.rdf4j.rio.RDFParseException; +import org.eclipse.rdf4j.sail.Sail; +import org.eclipse.rdf4j.sail.SailException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests loading files through a Accumulo {@link RyaSailFactory}. + */ +public class AccumuloRyaSailFactoryLoadFilesIT extends AccumuloITBase { + private static final Logger log = Logger.getLogger(AccumuloRyaSailFactoryLoadFilesIT.class); + + private RyaSailRepository ryaRepository; + private AccumuloRdfConfiguration conf; + + @Before + public void setupTest() throws Exception { + final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails( + getUsername(), + getPassword().toCharArray(), + getInstanceName(), + getZookeepers()); + + AccumuloRyaClientFactory.build(connectionDetails, getConnector()); + + conf = new AccumuloRdfConfiguration(); + conf.setUsername(getUsername()); + conf.setPassword(getPassword()); + conf.setInstanceName(getInstanceName()); + conf.setZookeepers(getZookeepers()); + conf.setTablePrefix(getRyaInstanceName()); + + ryaRepository = createRyaSailRepository(conf); + } + + @After + public void tearDown() throws Exception { + if (ryaRepository != null) { + close(ryaRepository); + } + } + + private static RyaSailRepository createRyaSailRepository(final RdfCloudTripleStoreConfiguration config) throws SailException { + log.info("Connecting to Sail Repository."); + + try { + final Sail extSail = RyaSailFactory.getInstance(config); + final RyaSailRepository repository = new RyaSailRepository(extSail); + return repository; + } catch (final Exception e) { + throw new SailException("Failed to create Rya Sail Repository", e); + } + } + + /** + * Shuts the repository down, releasing any resources that it keeps hold of. + * Once shut down, the repository can no longer be used until it is + * re-initialized. + * @param repository the {@link SailRepository} to close. + */ + private static void close(final SailRepository repository) { + if (repository != null) { + try { + repository.shutDown(); + } catch (final RepositoryException e) { + log.error("Encountered an error while closing Sail Repository", e); + } + } + } + + /** + * Closes the {@link SailRepositoryConnection}. + * @param conn the {@link SailRepositoryConnection}. + */ + private static void closeQuietly(final SailRepositoryConnection conn) { + if (conn != null) { + try { + conn.close(); + } catch (final RepositoryException e) { + // quietly absorb this exception + } + } + } + + private static void addTriples(final SailRepository repo, final InputStream triplesStream, final RDFFormat rdfFormat) throws RDFParseException, RepositoryException, IOException { + SailRepositoryConnection conn = null; + try { + conn = repo.getConnection(); + conn.begin(); + conn.add(triplesStream, "", rdfFormat); + conn.commit(); + } finally { + closeQuietly(conn); + } + } + + private static int performTupleQuery(final String query, final RepositoryConnection conn) throws RepositoryException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException { + final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); + tupleQuery.setMaxExecutionTime(10); + final CountingResultHandler handler = new CountingResultHandler(); + tupleQuery.evaluate(handler); + return handler.getCount(); + } + + @Test + public void testFileLoading() throws Exception { + log.info("Starting file loading test..."); + final String query = "SELECT * WHERE { ?s ?p ?o . FILTER(?p != <" + RdfCloudTripleStoreConstants.RTS_VERSION_PREDICATE + ">) }"; + final String deleteQuery = "DELETE WHERE { ?s ?p ?o . }"; + + for (final TestFile testFile : TestFileUtils.TEST_FILES) { + final String testFilePath = testFile.getPath(); + final RDFFormat rdfFormat = RdfFormatUtils.forFileName(testFilePath, null); + log.info("Loading file \"" + testFilePath + "\" with RDFFormat: " + rdfFormat.getName()); + try (final InputStream rdfContent = getClass().getResourceAsStream(testFilePath)) { + addTriples(ryaRepository, rdfContent, rdfFormat); + } + + SailRepositoryConnection queryConn = null; + try { + log.info("Querying for triples in the repository from the " + rdfFormat.getName() + " file."); + queryConn = ryaRepository.getConnection(); + final int count = performTupleQuery(query, queryConn); + assertEquals("Expected number of triples not found in: " + testFilePath, testFile.getExpectedCount(), count); + } finally { + closeQuietly(queryConn); + } + + SailRepositoryConnection deleteConn = null; + try { + log.info("Deleting triples in the repository from the " + rdfFormat.getName() + " file."); + deleteConn = ryaRepository.getConnection(); + final Update update = deleteConn.prepareUpdate(QueryLanguage.SPARQL, deleteQuery); + update.execute(); + } finally { + closeQuietly(deleteConn); + } + } + log.info("File loading test finished."); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/java/org/apache/rya/sail/config/MongoDbRyaSailFactoryLoadFilesIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/sail/config/MongoDbRyaSailFactoryLoadFilesIT.java b/extras/indexing/src/test/java/org/apache/rya/sail/config/MongoDbRyaSailFactoryLoadFilesIT.java new file mode 100644 index 0000000..bdca828 --- /dev/null +++ b/extras/indexing/src/test/java/org/apache/rya/sail/config/MongoDbRyaSailFactoryLoadFilesIT.java @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rya.sail.config; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.log4j.Logger; +import org.apache.rya.api.RdfCloudTripleStoreConfiguration; +import org.apache.rya.helper.TestFile; +import org.apache.rya.helper.TestFileUtils; +import org.apache.rya.indexing.mongo.MongoPcjIntegrationTest.CountingResultHandler; +import org.apache.rya.mongodb.MongoRyaITBase; +import org.apache.rya.rdftriplestore.RyaSailRepository; +import org.apache.rya.rdftriplestore.utils.RdfFormatUtils; +import org.eclipse.rdf4j.query.MalformedQueryException; +import org.eclipse.rdf4j.query.QueryEvaluationException; +import org.eclipse.rdf4j.query.QueryLanguage; +import org.eclipse.rdf4j.query.TupleQuery; +import org.eclipse.rdf4j.query.TupleQueryResultHandlerException; +import org.eclipse.rdf4j.query.Update; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryException; +import org.eclipse.rdf4j.repository.sail.SailRepository; +import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection; +import org.eclipse.rdf4j.rio.RDFFormat; +import org.eclipse.rdf4j.rio.RDFParseException; +import org.eclipse.rdf4j.sail.Sail; +import org.eclipse.rdf4j.sail.SailException; +import org.junit.After; +import org.junit.Test; + +/** + * Tests loading files through a MongoDB {@link RyaSailFactory}. + */ +public class MongoDbRyaSailFactoryLoadFilesIT extends MongoRyaITBase { + private static final Logger log = Logger.getLogger(MongoDbRyaSailFactoryLoadFilesIT.class); + + private RyaSailRepository ryaRepository; + + @Override + public void setupTest() throws Exception { + super.setupTest(); + + ryaRepository = createRyaSailRepository(conf); + } + + @After + public void tearDown() throws Exception { + if (ryaRepository != null) { + close(ryaRepository); + } + } + + private static RyaSailRepository createRyaSailRepository(final RdfCloudTripleStoreConfiguration config) throws SailException { + log.info("Connecting to Sail Repository."); + + try { + final Sail extSail = RyaSailFactory.getInstance(config); + final RyaSailRepository repository = new RyaSailRepository(extSail); + return repository; + } catch (final Exception e) { + throw new SailException("Failed to create Rya Sail Repository", e); + } + } + + /** + * Shuts the repository down, releasing any resources that it keeps hold of. + * Once shut down, the repository can no longer be used until it is + * re-initialized. + * @param repository the {@link SailRepository} to close. + */ + private static void close(final SailRepository repository) { + if (repository != null) { + try { + repository.shutDown(); + } catch (final RepositoryException e) { + log.error("Encountered an error while closing Sail Repository", e); + } + } + } + + /** + * Closes the {@link SailRepositoryConnection}. + * @param conn the {@link SailRepositoryConnection}. + */ + private static void closeQuietly(final SailRepositoryConnection conn) { + if (conn != null) { + try { + conn.close(); + } catch (final RepositoryException e) { + // quietly absorb this exception + } + } + } + + private static void addTriples(final SailRepository repo, final InputStream triplesStream, final RDFFormat rdfFormat) throws RDFParseException, RepositoryException, IOException { + SailRepositoryConnection conn = null; + try { + conn = repo.getConnection(); + conn.begin(); + conn.add(triplesStream, "", rdfFormat); + conn.commit(); + } finally { + closeQuietly(conn); + } + } + + private static int performTupleQuery(final String query, final RepositoryConnection conn) throws RepositoryException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException { + final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); + tupleQuery.setMaxExecutionTime(10); + final CountingResultHandler handler = new CountingResultHandler(); + tupleQuery.evaluate(handler); + return handler.getCount(); + } + + @Test + public void testFileLoading() throws Exception { + log.info("Starting file loading test..."); + final String query = "SELECT * WHERE { ?s ?p ?o . }"; + final String deleteQuery = "DELETE WHERE { ?s ?p ?o . }"; + + for (final TestFile testFile : TestFileUtils.TEST_FILES) { + final String testFilePath = testFile.getPath(); + final RDFFormat rdfFormat = RdfFormatUtils.forFileName(testFilePath, null); + log.info("Loading file \"" + testFilePath + "\" with RDFFormat: " + rdfFormat.getName()); + try (final InputStream rdfContent = getClass().getResourceAsStream(testFilePath)) { + addTriples(ryaRepository, rdfContent, rdfFormat); + } + + SailRepositoryConnection queryConn = null; + try { + log.info("Querying for triples in the repository from the " + rdfFormat.getName() + " file."); + queryConn = ryaRepository.getConnection(); + final int count = performTupleQuery(query, queryConn); + assertEquals("Expected number of triples not found in: " + testFilePath, testFile.getExpectedCount(), count); + } finally { + closeQuietly(queryConn); + } + + SailRepositoryConnection deleteConn = null; + try { + log.info("Deleting triples in the repository from the " + rdfFormat.getName() + " file."); + deleteConn = ryaRepository.getConnection(); + final Update update = deleteConn.prepareUpdate(QueryLanguage.SPARQL, deleteQuery); + update.execute(); + } finally { + closeQuietly(deleteConn); + } + } + log.info("File loading test finished."); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/resources/rdf_format_files/binary_data.brf ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/resources/rdf_format_files/binary_data.brf b/extras/indexing/src/test/resources/rdf_format_files/binary_data.brf new file mode 100644 index 0000000..f04d0c3 Binary files /dev/null and b/extras/indexing/src/test/resources/rdf_format_files/binary_data.brf differ http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/resources/rdf_format_files/jsonld_data.jsonld ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/resources/rdf_format_files/jsonld_data.jsonld b/extras/indexing/src/test/resources/rdf_format_files/jsonld_data.jsonld new file mode 100644 index 0000000..84025cf --- /dev/null +++ b/extras/indexing/src/test/resources/rdf_format_files/jsonld_data.jsonld @@ -0,0 +1,17 @@ +{ + "@context": + { + "name": "http://rya.apache.org/ns/name", + "image": { + "@id": "http://rya.apache.org/ns/image", + "@type": "@id" + }, + "homepage": { + "@id": "http://rya.apache.org/ns/url", + "@type": "@id" + } + }, + "name": "Bob Smitch", + "homepage": "http://rya.apache.org/bobs_homepage", + "image": "http://rya.apache.org/bobs_homepage/images/bobs_party.jpg" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/resources/rdf_format_files/n3_data.n3 ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/resources/rdf_format_files/n3_data.n3 b/extras/indexing/src/test/resources/rdf_format_files/n3_data.n3 new file mode 100644 index 0000000..3d48fdf --- /dev/null +++ b/extras/indexing/src/test/resources/rdf_format_files/n3_data.n3 @@ -0,0 +1,14 @@ +@prefix : <http://rya.apache.org/ns/sports#> . + +:Bob :plays :Football . +:Susan :coaches :Football . +:Bob :givenName "Robert" . +:Bob :aka "Bob"@en-US . +:Bob :aka "Robert"@en-GB . +:Bob :aka "Roberto"@es . +:Bob :aka "Roberto"@es-MEX . +:Bob :aka "Roberto"@spa . +:Bob :aka "Roberto"@spa-ESP . +:Bob :aka "Robert"@de . +:Bob :aka "Rupert"@de-DE . +:Bob :aka "#!$*(&^"@und . \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/resources/rdf_format_files/nquads_data.nq ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/resources/rdf_format_files/nquads_data.nq b/extras/indexing/src/test/resources/rdf_format_files/nquads_data.nq new file mode 100644 index 0000000..7948bff --- /dev/null +++ b/extras/indexing/src/test/resources/rdf_format_files/nquads_data.nq @@ -0,0 +1,2 @@ +<http://rya.apache.org/ns/Bob> <http://rya.apache.org/ns/hasJob> <http://rya.apache.org/ns/Programmer> <http://rya.apache.org/ns/graph1> . +<http://rya.apache.org/ns/Susan> <http://rya.apache.org/ns/hasJob> <http://rya.apache.org/ns/Manager> <http://rya.apache.org/ns/graph2> . \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/resources/rdf_format_files/ntriples_data.nt ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/resources/rdf_format_files/ntriples_data.nt b/extras/indexing/src/test/resources/rdf_format_files/ntriples_data.nt new file mode 100644 index 0000000..bbd3b37 --- /dev/null +++ b/extras/indexing/src/test/resources/rdf_format_files/ntriples_data.nt @@ -0,0 +1,3 @@ +<http://rya.apache.org/ns/Bobs_Book> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rya.apache.org/ns/Book> . +<http://rya.apache.org/ns/Bobs_Book> <http://www.w3.org/2000/01/rdf-schema#label> "The Book of Smitch" . +<http://rya.apache.org/ns/Bobs_Book> <http://rya.apache.org/ns/publishedBy> <http://rya.apache.org/ns/DillonPublishing> . \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/resources/rdf_format_files/rdfjson_data.rj ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/resources/rdf_format_files/rdfjson_data.rj b/extras/indexing/src/test/resources/rdf_format_files/rdfjson_data.rj new file mode 100644 index 0000000..fbb665a --- /dev/null +++ b/extras/indexing/src/test/resources/rdf_format_files/rdfjson_data.rj @@ -0,0 +1,7 @@ +{ + "http://rya.apache.org/ns/" : { + "http://rya.apache.org/ns/title/" : [ { "value" : "Bob's Homepage", + "type" : "literal", + "lang" : "en" } ] + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/resources/rdf_format_files/rdfxml_data.owl ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/resources/rdf_format_files/rdfxml_data.owl b/extras/indexing/src/test/resources/rdf_format_files/rdfxml_data.owl new file mode 100644 index 0000000..4d55cdb --- /dev/null +++ b/extras/indexing/src/test/resources/rdf_format_files/rdfxml_data.owl @@ -0,0 +1,12 @@ +<?xml version="1.0"?> + +<rdf:RDF +xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" +xmlns:books="http://rya.apache.org/ns/"> + + <rdf:Description> + <books:title>Rya Rocks</books:title> + <books:author>Bob Smitch</books:author> + </rdf:Description> + +</rdf:RDF> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/resources/rdf_format_files/trig_data.trig ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/resources/rdf_format_files/trig_data.trig b/extras/indexing/src/test/resources/rdf_format_files/trig_data.trig new file mode 100644 index 0000000..c2f93b6 --- /dev/null +++ b/extras/indexing/src/test/resources/rdf_format_files/trig_data.trig @@ -0,0 +1,10 @@ +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . +@prefix personnel: <http://rya.apache.org/ns/personnel/> . +@prefix : <http://rya.apache.org/ns/> . + +:Graph1 { :Bob personnel:name "Bob Smitch" . + :Bob personnel:email <mailto:[email protected]> . + :Bob personnel:hasSkill personnel:Programming } + +:Graph2 { :Susan rdf:type personnel:Person . + :Susan personnel:hasSkill personnel:Management } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/resources/rdf_format_files/trix_data.trix ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/resources/rdf_format_files/trix_data.trix b/extras/indexing/src/test/resources/rdf_format_files/trix_data.trix new file mode 100644 index 0000000..192be8d --- /dev/null +++ b/extras/indexing/src/test/resources/rdf_format_files/trix_data.trix @@ -0,0 +1,19 @@ +<TriX> + <graph> + <triple> + <uri>http://rya.apache.org/ns/person#Bob</uri> + <uri>http://rya.apache.org/ns/relation#wife</uri> + <uri>http://rya.apache.org/ns/person#Susan</uri> + </triple> + <triple> + <uri>http://rya.apache.org/ns/person#Bob</uri> + <uri>http://rya.apache.org/ns/name</uri> + <plainLiteral>Bob</plainLiteral> + </triple> + <triple> + <uri>http://rya.apache.org/ns/person#Mary</uri> + <uri>http://rya.apache.org/ns/age</uri> + <typedLiteral datatype="http://www.w3.org/2001/XMLSchema#integer">32</typedLiteral> + </triple> + </graph> +</TriX> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2396ebb8/extras/indexing/src/test/resources/rdf_format_files/turtle_data.ttl ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/resources/rdf_format_files/turtle_data.ttl b/extras/indexing/src/test/resources/rdf_format_files/turtle_data.ttl new file mode 100644 index 0000000..698e3ba --- /dev/null +++ b/extras/indexing/src/test/resources/rdf_format_files/turtle_data.ttl @@ -0,0 +1,11 @@ +@prefix contacts: <http://rya.apache.org/ns/contacts#> . + +contacts:bob contacts:homePhone "(555) 555-1234" . +contacts:bob contacts:emailAddress "[email protected]" . + +contacts:susan contacts:homePhone "(555) 555-4321" . +contacts:susan contacts:emailAddress "[email protected]" . + +contacts:ron contacts:homePhone "(555) 555-9876" . +contacts:ron contacts:emailAddress "[email protected]" . +contacts:ron contacts:emailAddress "[email protected]" . \ No newline at end of file
