示例#1
0
        def setUp(self):
            super(BaseTestBuildThing.TestBuildThing, self).setUp()

            self._grakn_thing = list(self._tx.query(self.query))[0].get(
                self.var)

            self._thing = neighbour.build_thing(self._grakn_thing)
示例#2
0
    def setUpClass(cls):
        client = grakn.client.GraknClient(uri="localhost:48555")
        cls.session = client.session(keyspace="test_schema")

        entity_query = "match $x isa company, has name 'Google'; get;"
        cls._tx = cls.session.transaction().write()

        neighbour_sample_sizes = (4, 3)

        sampling_method = ordered.ordered_sample

        samplers = []
        for sample_size in neighbour_sample_sizes:
            samplers.append(
                samp.Sampler(sample_size,
                             sampling_method,
                             limit=sample_size * 2))

        grakn_thing = next(cls._tx.query(entity_query)).get('x')

        thing = neighbour.build_thing(grakn_thing)

        context_builder = builder.ContextBuilder(samplers)

        cls.context = context_builder.build(cls._tx, thing)
示例#3
0
    def setUp(self):
        entity_query = "match $x isa company, has name 'Google'; get;"
        uri = "localhost:48555"
        keyspace = "test_schema"
        client = grakn.Grakn(uri=uri)
        session = client.session(keyspace=keyspace)
        self._tx = session.transaction(grakn.TxType.WRITE)

        neighbour_sample_sizes = (4, 3)

        sampling_method = ordered.ordered_sample

        samplers = []
        for sample_size in neighbour_sample_sizes:
            samplers.append(samp.Sampler(sample_size, sampling_method, limit=sample_size * 2))

        grakn_things = [answermap.get('x') for answermap in list(self._tx.query(entity_query))]

        things = [neighbour.build_thing(grakn_thing) for grakn_thing in grakn_things]

        context_builder = builder.ContextBuilder(samplers)

        self._neighbourhood_depths = [context_builder.build(self._tx, thing) for thing in things]

        self._neighbour_roles = builder.convert_thing_contexts_to_neighbours(self._neighbourhood_depths)

        self._flattened = flatten_tree(self._neighbour_roles)
示例#4
0
    def setUp(self):
        self._tx = self.session.transaction(grakn.TxType.WRITE)

        # identifier = "Jacob J. Niesz"
        # entity_query = "match $x isa person, has identifier '{}'; get $x;".format(identifier)
        entity_query = "match $x isa person, has name 'Sundar Pichai'; get;"

        self._thing = neighbour.build_thing(list(self._tx.query(entity_query))[0].get('x'))
示例#5
0
    def build_batch(self, session: grakn.Session, grakn_things: typ.List[neighbour.Thing]):
        things = [neighbour.build_thing(grakn_thing) for grakn_thing in grakn_things]

        thing_contexts = []
        for thing in things:
            tx = session.transaction(grakn.TxType.WRITE)
            print(f'Opening transaction {tx}')
            thing_context = self.build(tx, thing)
            thing_contexts.append(thing_context)
            print(f'closing transaction {tx}')
            tx.close()
        context_batch = convert_thing_contexts_to_neighbours(thing_contexts)

        return context_batch