use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.
the class DisjunctiveNormalFormConverterTest method testConvertToDnf.
/**
* Test ability to convert expressions into Disjunctive Normal Form.
*/
@Test
public void testConvertToDnf() {
for (final Pair<String, String> pair : INPUT_AND_EXPECTED_BOOLEAN_EXPRESSIONS) {
final String input = pair.getLeft();
final String expected = pair.getRight();
final DocumentVisibility inputDv = new DocumentVisibility(input);
final DocumentVisibility resultDv = DisjunctiveNormalFormConverter.convertToDisjunctiveNormalForm(inputDv);
assertEquals(expected, new String(resultDv.flatten()));
}
}
use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.
the class DisjunctiveNormalFormConverterTest method testTruthTableSize3FromNode.
/**
* Test truth table with 3 inputs from a node.
*/
@Test
public void testTruthTableSize3FromNode() {
final DocumentVisibility dv = new DocumentVisibility("(A&B)|(A&C)");
final byte[][] truthTable = DisjunctiveNormalFormConverter.createTruthTableInputs(dv.getParseTree(), dv.getExpression());
final byte[][] expected = { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 0 }, { 0, 1, 1 }, { 1, 0, 0 }, { 1, 0, 1 }, { 1, 1, 0 }, { 1, 1, 1 } };
assertArrayEquals(expected, truthTable);
}
use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.
the class DisjunctiveNormalFormConverterTest method testTruthTableNullExpression.
/**
* Test truth table with a {@code null} expression.
*/
@Test(expected = NullPointerException.class)
public void testTruthTableNullExpression() {
final Node node = new DocumentVisibility("A").getParseTree();
final byte[] expression = null;
DisjunctiveNormalFormConverter.createTruthTableInputs(node, expression);
}
use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.
the class DocumentVisibilityUtil method multidimensionalArrayToBooleanString.
/**
* Converts a multidimensional array object representation of the document
* visibility boolean expression into a string.
* @param object the multidimensional array object representing the
* document visibility boolean expression.
* @return the boolean string expression.
*/
public static String multidimensionalArrayToBooleanString(final Object[] object) {
final String booleanString = multidimensionalArrayToBooleanStringInternal(object);
// Simplify and clean up the formatting.
final DocumentVisibility dv = DisjunctiveNormalFormConverter.createDnfDocumentVisibility(booleanString);
final byte[] bytes = dv.flatten();
final String result = new String(bytes, Charsets.UTF_8);
return result;
}
use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.
the class MongoDBRyaDAOIT method testReconstructDao.
@Test
public void testReconstructDao() throws RyaDAOException, IOException {
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
final RyaStatementBuilder builder = new RyaStatementBuilder();
builder.setPredicate(new RyaURI("http://temp.com"));
builder.setSubject(new RyaURI("http://subject.com"));
builder.setObject(new RyaURI("http://object.com"));
builder.setColumnVisibility(new DocumentVisibility("B").flatten());
final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
dao.add(builder.build());
assertEquals(coll.count(), 1);
final Document dbo = coll.find().first();
assertTrue(dbo.containsKey(DOCUMENT_VISIBILITY));
assertTrue(dbo.containsKey(TIMESTAMP));
} finally {
dao.destroy();
}
// Test reinitializing the same instance
try {
dao.init();
} finally {
dao.destroy();
}
// Reconstruct new DAO and try again
dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
final RyaStatementBuilder builder = new RyaStatementBuilder();
builder.setPredicate(new RyaURI("http://temp.com"));
builder.setSubject(new RyaURI("http://subject.com"));
builder.setObject(new RyaURI("http://object.com"));
builder.setColumnVisibility(new DocumentVisibility("B").flatten());
final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
dao.add(builder.build());
assertEquals(coll.count(), 1);
final Document dbo = coll.find().first();
assertTrue(dbo.containsKey(DOCUMENT_VISIBILITY));
assertTrue(dbo.containsKey(TIMESTAMP));
} finally {
dao.destroy();
}
}
Aggregations