def _function_calls(self, query, include_implicit, include_metatypes): exec = ex.TraversalExecutor(self._tx) schema_concept_types = exec.get_schema_concept_types( query, include_implicit=include_implicit, include_metatypes=include_metatypes) labels = trv.labels_from_types(schema_concept_types) return labels
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()]
def test_integration(self): client = grakn.Grakn(uri="localhost:48555") session = client.session(keyspace="test_schema") tx = session.transaction(grakn.TxType.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()]
def __init__(self, schema_tx): ################################################################################################################ # Schema Traversals ################################################################################################################ # This depends upon the schema being the same for the keyspace used in training vs eval and predict schema_traversal_executor = schema_ex.TraversalExecutor(schema_tx) # THINGS thing_schema_traversal = trav.traverse_schema( schema_traversal_executor, GET_THING_TYPES_QUERY) # ROLES role_schema_traversal = trav.traverse_schema(schema_traversal_executor, GET_ROLE_TYPES_QUERY) role_schema_traversal['has'] = ['has'] ############################################################################################################ # Encoders Initialisation ############################################################################################################ with tf.name_scope('encoding_init') as scope: thing_encoder = schema.MultiHotSchemaTypeEncoder( thing_schema_traversal, name='thing_encoder') role_encoder = schema.MultiHotSchemaTypeEncoder( role_schema_traversal, name='role_encoder') # In case of issues https://github.com/tensorflow/hub/issues/61 string_encoder = tf_hub.TensorFlowHubEncoder( "https://tfhub.dev/google/nnlm-en-dim128-with-normalization/1", 128) data_types = list(neighbour.DATA_TYPE_NAMES) data_types.insert( 0, NO_DATA_TYPE ) # For the case where an entity or relation is encountered data_types_traversal = { data_type: data_types for data_type in data_types } # Later a hierarchy could be added to data_type meaning. e.g. long and double are both numeric data_type_encoder = schema.MultiHotSchemaTypeEncoder( data_types_traversal, name='data_type_encoder') self._encoders = { 'role_type': role_encoder, 'role_direction': lambda x: tf.to_float(x, 'role_dir_to_float'), 'neighbour_type': thing_encoder, 'neighbour_data_type': lambda x: data_type_encoder(tf.convert_to_tensor(x)), 'neighbour_value_long': lambda x: tf.to_float(x, name='long_to_float'), 'neighbour_value_double': lambda x: x, 'neighbour_value_boolean': lambda x: tf.to_float(boolean.one_hot_boolean_encode( x, 'boolean_1_hot'), name='boolean_to_float'), 'neighbour_value_date': lambda x: tf.nn.l2_normalize(tf.to_float(x, name='date_to_float')), 'neighbour_value_string': string_encoder }