Discussion Forum

How to explore an unknown grakn db?

With an unknown grakn db, how to explore it? By which means, how to check defined of entity, attribute and relation? Any command line examples?

Thanks!

Hi!

To explore a database that you have no knowledge of, first try making queries of the schema. Here are some ideas:
match $x sub thing; - get all types of thing
match $x sub entity; - get all types of entity
match $x sub relation; - get all types of relation
match some-relation relates $role; - get the roles of a relation
match $x plays some-relation:some-role; - get the types playing a certain role

Essentially, play around with the keywords sub, sub!, relates, plays and you should get an idea of what the schema looks like. You can also try visualising this, or export the schema from the console to inspect it in full as TypeQL.

@james Thanks to you information, I did get what I want through console command line. My problem now is how to get those from python code. Here is the example:
Assue the grakn has jyyj keyspace which has those entities:

How to get those entity names from python code?
I tried

client  = GraknClient(uri="localhost:48555")
session = client.session(keyspace="jyyj")
grakn_read = session.transaction().read()
cmd = "match $x sub entity;get $x;"
_re = grakn_read.query(cmd)
  if _re:
    for c in _re:
      print(c,c.map(),c.map().get("x"),c.query_pattern())
session.close()
client.close()

But here is the error msg:

In the document, I can’t find how to retrieve the entity names through python code.

I note that you’re still using Grakn and not TypeDB - please do upgrade to TypeDB as soon as you can, it’s a rewrite of Grakn that’s much faster and has maintained documentation.

Because of that I can’t remember for sure the method you need. You have queried for a Type, so you need to use the Type methods on the concept x.

It should be something similar to TypeDB where we use type.get_label().name() (see the Python tab in the docs entry here: Type | Vaticle)

I actually don’t see any reason why you should be getting an AttributeError here. This error says you’re trying to ask for the value of an EntityType. Only Attributes have values, which is why this is an error. I would expect to see this error from a call in your code like c.map().get_value(), but I don’t see that.

@james The reason I’ve to use Grakn is that TypeDB doesn’t support computing path yet (such as the shotest path).

I’m building a UI for knowledge graph management using Grakn 1.8.4 as the backend. But I don’t know how to get all entities/attributes/attributes from the Grakn through python client. I’m reading the doc (docs/04-concept-api/references at 80ba09226ad666dea44f788898f04eac18c25cab · vaticle/docs · GitH), but due to lack of context of code, I can’t get the method function right.

Need some help or more information here, if possible.

Thanks,
Zack

I think you’re nearly looking in the right place, but you want this:

Which says you need type().label() for Grakn 1.8.4. The method you need is common to all Types so it’s there. In general for future issues you may encounter, you may find it faster to read the source code of the Python client directly. You can navigate there by looking up the release that you are using here: Releases · vaticle/typedb-client-python · GitHub . On the left you can click on the commit hash and then browse files. For client-python 1.8.1 it’s here: GitHub - vaticle/typedb-client-python at eaabaf938bd8c763fcfbfe1ba7ea94adfc9f8214

You’ll find most of what you need in grakn/service/Session/Concept/Concept.py
and in grakn/service/Session/Concept/RemoteConcept.py. For the latter you’ll need to use concept.asRemote(tx) before you can access those methods (the concept object will fetch the data you ask for from the server when you use these methods).