Esempio n. 1
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)
Esempio n. 2
0
    def test_integration(self):
        client = grakn.client.GraknClient(uri=TEST_URI)
        session = client.session(keyspace=TEST_KEYSPACE)
        tx = session.transaction().write()

        print("================= THINGS ======================")
        te = ex.TraversalExecutor(tx)
        schema_concept_types = te.get_schema_concept_types(
            encode.GET_THING_TYPES_QUERY,
            include_implicit=True,
            include_metatypes=False)
        labels = trv.labels_from_types(schema_concept_types)
        print(list(labels))

        schema_concept_types = te.get_schema_concept_types(
            encode.GET_THING_TYPES_QUERY,
            include_implicit=True,
            include_metatypes=False)
        super_types = trv.get_sups_labels_per_type(schema_concept_types,
                                                   include_self=True,
                                                   include_metatypes=False)
        print("==== super types ====")
        [print(type, super_types) for type, super_types in super_types.items()]

        print("================= ROLES ======================")
        schema_concept_types = te.get_schema_concept_types(
            encode.GET_ROLE_TYPES_QUERY,
            include_implicit=True,
            include_metatypes=False)
        labels = trv.labels_from_types(schema_concept_types)
        print(list(labels))

        schema_concept_types = te.get_schema_concept_types(
            encode.GET_ROLE_TYPES_QUERY,
            include_implicit=True,
            include_metatypes=False)
        super_types = trv.get_sups_labels_per_type(schema_concept_types,
                                                   include_self=True,
                                                   include_metatypes=False)
        print("==== super types ====")
        [print(type, super_types) for type, super_types in super_types.items()]
Esempio n. 3
0
import grakn.client

training_keyspace= "dm_graph"
neighbour_sample_sizes= [7,2,2]
features_size= 10
example_things_features_size= 5
aggregated_size= 20
embedding_size= 32
batch_size= 10
learning_rate= .1
num_classes=

URI = "172.16.253.242:48555"

client = grakn.client.GraknClient(uri=URI)
session = client.session(keyspace=training_keyspace)
transaction = session.transaction().write()

kgcn = model.KGCN(neighbour_sample_sizes,
                  features_size,
                  example_things_features_size,
                  aggregated_size,
                  embedding_size,
                  transaction,
                  batch_size)

optimizer = tf.train.GradientDescentOptimizer(learning_rate=learning_rate)

classifier = classify.SupervisedKGCNMultiClassSingleLabelClassifier(kgcn,
                                               optimizer, 
                                               num_classes, 
Esempio n. 4
0
 def setUp(self):
     client = grakn.client.GraknClient(uri=TEST_URI)
     session = client.session(keyspace=TEST_KEYSPACE)
     self._tx = session.transaction().write()
Esempio n. 5
0
    def test_encode(self):
        client = grakn.client.GraknClient(uri=TEST_URI)
        session = client.session(keyspace=TEST_KEYSPACE)
        tx = session.transaction().write()
        encoder = encode.Encoder(tx)

        placeholders = [{
            'role_type':
            tf.placeholder(dtype=tf.string, shape=(None, 1)),
            'role_direction':
            tf.placeholder(dtype=tf.int64, shape=(None, 1)),
            'neighbour_type':
            tf.placeholder(dtype=tf.string, shape=(None, 1)),
            'neighbour_data_type':
            tf.placeholder(dtype=tf.string, shape=(None, 1)),
            'neighbour_value_long':
            tf.placeholder(dtype=tf.int64, shape=(None, 1)),
            'neighbour_value_double':
            tf.placeholder(dtype=tf.float32, shape=(None, 1)),
            'neighbour_value_boolean':
            tf.placeholder(dtype=tf.int64, shape=(None, 1)),
            'neighbour_value_date':
            tf.placeholder(dtype=tf.int64, shape=(None, 1)),
            'neighbour_value_string':
            tf.placeholder(dtype=tf.string, shape=(None, 1))
        }]

        encoded_output = encoder(placeholders)

        example_arrays = {
            'role_type':
            np.full((4, 1), fill_value='employee', dtype=np.dtype('U50')),
            'role_direction':
            np.full((4, 1), fill_value=0, dtype=np.int),
            'neighbour_type':
            np.full((4, 1), fill_value='person', dtype=np.dtype('U50')),
            'neighbour_data_type':
            np.full((4, 1), fill_value='', dtype=np.dtype('U10')),
            'neighbour_value_long':
            np.full((4, 1), fill_value=0, dtype=np.int),
            'neighbour_value_double':
            np.full((4, 1), fill_value=0.0, dtype=np.float),
            'neighbour_value_boolean':
            np.full((4, 1), fill_value=0, dtype=np.int),
            'neighbour_value_date':
            np.full((4, 1), fill_value=0, dtype=np.int),
            'neighbour_value_string':
            np.full((4, 1), fill_value='', dtype=np.dtype('U50'))
        }

        feed_dict = {
            placeholder: example_arrays[placeholder_name]
            for placeholder_name, placeholder in placeholders[0].items()
        }

        init_global = tf.global_variables_initializer()
        init_tables = tf.tables_initializer()

        tf_session = tf.Session()
        tf_session.run(init_global)
        tf_session.run(init_tables)

        tf_session.run(encoded_output, feed_dict=feed_dict)
Esempio n. 6
0
 def setUp(self):
     client = grakn.client.GraknClient(uri="localhost:48555")
     session = client.session(keyspace="test_schema")
     self._tx = session.transaction().write()
Esempio n. 7
0
 def setUpClass(cls):
     client = grakn.client.GraknClient(uri=TEST_URI)
     cls.session = client.session(keyspace=cls.keyspace)