def test_join_binary(self): clan1 = Set(Set([Couplet(1, 'one')])) clan2 = Set(Set([Couplet(2, 'two')])) answer = Set(Set([Couplet(1, 'one'), Couplet(2, 'two')])) joined = join(clan1, clan2) # data is unordered so don't use equality, use symmetric difference self.assertEqual(0, len(answer.data ^ joined.data))
def test_join_quaternary(self): clan1 = Set(Set([Couplet(1, 'one')])) clan2 = Set(Set([Couplet(2, 'two')])) clan3 = Set(Set([Couplet(3, 'three')])) clan4 = Set(Set([Couplet(4, 'four')])) answer = Set(Set(Couplet(1, 'one'), Couplet(2, 'two'), Couplet(3, 'three'), Couplet(4, 'four'))) joined = join(clan1, clan2, clan3, clan4) # data is unordered so don't use equality, use symmetric difference self.assertEqual(0, len(answer.data ^ joined.data))
def test_join_quaternary(self): clan1 = Set(Set([Couplet(1, 'one')])) clan2 = Set(Set([Couplet(2, 'two')])) clan3 = Set(Set([Couplet(3, 'three')])) clan4 = Set(Set([Couplet(4, 'four')])) answer = Set( Set(Couplet(1, 'one'), Couplet(2, 'two'), Couplet(3, 'three'), Couplet(4, 'four'))) joined = join(clan1, clan2, clan3, clan4) # data is unordered so don't use equality, use symmetric difference self.assertEqual(0, len(answer.data ^ joined.data))
# Data Algebra ------------------------------------------------------------------------------------- # Import the example graph as data algebra MathObject. graph_algebra = import_graph(io.StringIO(sample_graph), rdf_format='turtle') if print_examples: print('Input graph (as MathObject):', graph_algebra) # Query the MathObject graph, retrieving the id, name and favorite MathObject of all engineers who # have all three. start = time() engineers_algebra = join( triple_match(graph_algebra, '?eng', rdflib.URIRef('rdf:name'), '?name'), triple_match(graph_algebra, '?eng', rdflib.URIRef('rdf:type'), rdflib.URIRef('cat:engineer')), triple_match(graph_algebra, '?eng', rdflib.URIRef('fav:mathobject'), '?fav') ) elapsed_algebra = time() - start engineers_algebra_json = io.StringIO() export_table( file_or_path=engineers_algebra_json, lefts=Set(['?eng', '?name', '?fav']), table=engineers_algebra, out_format='json') if print_examples: print('Engineers (data algebra API, took {time:.3f} s): {result}'.format( time=elapsed_algebra, result=engineers_algebra)) print('The data in RDF JSON:\n{json}'.format(json=engineers_algebra_json.getvalue()))