Search in sources :

Example 41 with RyaURI

use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.

the class MongoEntityStorage method searchHasAllExplicitTypes.

/**
 * Searches the Entity storage for all Entities that contain all the
 * specified explicit type IDs.
 * @param explicitTypeIds the {@link ImmutableList} of {@link RyaURI}s that
 * are being searched for.
 * @return the {@link List} of {@link Entity}s that have all the specified
 * explicit type IDs. If nothing was found an empty {@link List} is
 * returned.
 * @throws EntityStorageException
 */
private List<Entity> searchHasAllExplicitTypes(final ImmutableList<RyaURI> explicitTypeIds) throws EntityStorageException {
    final List<Entity> hasAllExplicitTypesEntities = new ArrayList<>();
    if (!explicitTypeIds.isEmpty()) {
        // Grab the first type from the explicit type IDs.
        final RyaURI firstType = explicitTypeIds.get(0);
        // Check if that type exists anywhere in storage.
        final List<RyaURI> subjects = new ArrayList<>();
        Optional<Type> type;
        try {
            if (mongoTypeStorage == null) {
                mongoTypeStorage = new MongoTypeStorage(mongo, ryaInstanceName);
            }
            type = mongoTypeStorage.get(firstType);
        } catch (final TypeStorageException e) {
            throw new EntityStorageException("Unable to get entity type: " + firstType, e);
        }
        if (type.isPresent()) {
            // Grab the subjects for all the types we found matching "firstType"
            final ConvertingCursor<TypedEntity> cursor = search(Optional.empty(), type.get(), Collections.emptySet());
            while (cursor.hasNext()) {
                final TypedEntity typedEntity = cursor.next();
                final RyaURI subject = typedEntity.getSubject();
                subjects.add(subject);
            }
        }
        // Now grab all the Entities that have the subjects we found.
        for (final RyaURI subject : subjects) {
            final Optional<Entity> entityFromSubject = get(subject);
            if (entityFromSubject.isPresent()) {
                final Entity candidateEntity = entityFromSubject.get();
                // types they have.
                if (candidateEntity.getExplicitTypeIds().containsAll(explicitTypeIds)) {
                    hasAllExplicitTypesEntities.add(candidateEntity);
                }
            }
        }
    }
    return hasAllExplicitTypesEntities;
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) ArrayList(java.util.ArrayList) TypeStorageException(org.apache.rya.indexing.entity.storage.TypeStorage.TypeStorageException) RyaURI(org.apache.rya.api.domain.RyaURI) Type(org.apache.rya.indexing.entity.model.Type) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity)

Example 42 with RyaURI

use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.

the class RdfCloudTripleStoreConfiguration method getStatementMetadataProperties.

public Set<RyaURI> getStatementMetadataProperties() {
    final Set<RyaURI> uriSet = new HashSet<>();
    final String[] uriStrings = getStrings(CONF_STATEMENT_METADATA_PROPERTIES);
    if (uriStrings != null) {
        for (final String s : uriStrings) {
            uriSet.add(new RyaURI(s));
        }
    }
    return uriSet;
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) HashSet(java.util.HashSet)

Example 43 with RyaURI

use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.

the class RdfCloudTripleStoreConfiguration method setStatementMetadataProperties.

public void setStatementMetadataProperties(final Set<RyaURI> metadataProperties) {
    final String[] propArray = new String[metadataProperties.size()];
    int i = 0;
    for (final RyaURI uri : metadataProperties) {
        propArray[i] = uri.getData();
        i++;
    }
    setStrings(CONF_STATEMENT_METADATA_PROPERTIES, propArray);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI)

Example 44 with RyaURI

use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.

the class WholeRowHashedTripleResolver method serialize.

@Override
public Map<TABLE_LAYOUT, TripleRow> serialize(final RyaStatement stmt) throws TripleRowResolverException {
    try {
        final RyaURI subject = stmt.getSubject();
        final RyaURI predicate = stmt.getPredicate();
        final RyaType object = stmt.getObject();
        final RyaURI context = stmt.getContext();
        final Long timestamp = stmt.getTimestamp();
        final byte[] columnVisibility = stmt.getColumnVisibility();
        final String qualifer = stmt.getQualifer();
        final byte[] qualBytes = qualifer == null ? EMPTY_BYTES : qualifer.getBytes(StandardCharsets.UTF_8);
        final byte[] value = stmt.getValue();
        assert subject != null && predicate != null && object != null;
        final byte[] cf = (context == null) ? EMPTY_BYTES : context.getData().getBytes(StandardCharsets.UTF_8);
        final Map<TABLE_LAYOUT, TripleRow> tripleRowMap = new HashMap<TABLE_LAYOUT, TripleRow>();
        final MessageDigest md = MessageDigest.getInstance("MD5");
        final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8);
        final byte[] subjHashBytes = md.digest(subjBytes);
        final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
        final byte[] predHashBytes = md.digest(predBytes);
        final byte[][] objBytes = RyaContext.getInstance().serializeType(object);
        tripleRowMap.put(TABLE_LAYOUT.SPO, new TripleRow(Bytes.concat(Hex.encodeHexString(subjHashBytes).getBytes(StandardCharsets.UTF_8), DELIM_BYTES, subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes[0], objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
        tripleRowMap.put(TABLE_LAYOUT.PO, new TripleRow(Bytes.concat(Hex.encodeHexString(predHashBytes).getBytes(StandardCharsets.UTF_8), DELIM_BYTES, predBytes, DELIM_BYTES, objBytes[0], DELIM_BYTES, subjBytes, objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
        tripleRowMap.put(TABLE_LAYOUT.OSP, new TripleRow(Bytes.concat(objBytes[0], DELIM_BYTES, subjBytes, DELIM_BYTES, predBytes, objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
        return tripleRowMap;
    } catch (final RyaTypeResolverException e) {
        throw new TripleRowResolverException(e);
    } catch (final NoSuchAlgorithmException e) {
        throw new TripleRowResolverException(e);
    }
}
Also used : HashMap(java.util.HashMap) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) RyaType(org.apache.rya.api.domain.RyaType) TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) RyaURI(org.apache.rya.api.domain.RyaURI) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) RyaTypeResolverException(org.apache.rya.api.resolver.RyaTypeResolverException) MessageDigest(java.security.MessageDigest)

Example 45 with RyaURI

use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.

the class MongoFreeTextIndexerIT method testRestrictPredicatesSearch.

@Test
public void testRestrictPredicatesSearch() throws Exception {
    conf.setStrings(ConfigUtils.FREETEXT_PREDICATES_LIST, "pred:1,pred:2");
    try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
        f.setConf(conf);
        f.init();
        // These should not be stored because they are not in the predicate list
        f.storeStatement(new RyaStatement(new RyaURI("foo:subj1"), new RyaURI(RDFS.LABEL.toString()), new RyaType("invalid")));
        f.storeStatement(new RyaStatement(new RyaURI("foo:subj2"), new RyaURI(RDFS.COMMENT.toString()), new RyaType("invalid")));
        final RyaURI pred1 = new RyaURI("pred:1");
        final RyaURI pred2 = new RyaURI("pred:2");
        // These should be stored because they are in the predicate list
        final RyaStatement s3 = new RyaStatement(new RyaURI("foo:subj3"), pred1, new RyaType("valid"));
        final RyaStatement s4 = new RyaStatement(new RyaURI("foo:subj4"), pred2, new RyaType("valid"));
        f.storeStatement(s3);
        f.storeStatement(s4);
        // This should not be stored because the object is not a literal
        f.storeStatement(new RyaStatement(new RyaURI("foo:subj5"), pred1, new RyaURI("in:validURI")));
        f.flush();
        assertEquals(Sets.newHashSet(), getSet(f.queryText("invalid", EMPTY_CONSTRAINTS)));
        assertEquals(Sets.newHashSet(), getSet(f.queryText("in:validURI", EMPTY_CONSTRAINTS)));
        final Set<Statement> actual = getSet(f.queryText("valid", EMPTY_CONSTRAINTS));
        assertEquals(2, actual.size());
        assertTrue(actual.contains(RyaToRdfConversions.convertStatement(s3)));
        assertTrue(actual.contains(RyaToRdfConversions.convertStatement(s4)));
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) MongoFreeTextIndexer(org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer) Test(org.junit.Test)

Aggregations

RyaURI (org.apache.rya.api.domain.RyaURI)287 Test (org.junit.Test)190 RyaStatement (org.apache.rya.api.domain.RyaStatement)183 RyaType (org.apache.rya.api.domain.RyaType)146 BindingSet (org.openrdf.query.BindingSet)56 ArrayList (java.util.ArrayList)52 StatementPattern (org.openrdf.query.algebra.StatementPattern)50 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)49 HashSet (java.util.HashSet)43 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)43 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)42 ParsedQuery (org.openrdf.query.parser.ParsedQuery)42 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)42 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)35 Entity (org.apache.rya.indexing.entity.model.Entity)30 Property (org.apache.rya.indexing.entity.model.Property)28 URIImpl (org.openrdf.model.impl.URIImpl)25 EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)22 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)21 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)21