New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieving all attribute types owned by a concept type #4664

Open
MCSH opened this Issue Nov 26, 2018 · 7 comments

Comments

5 participants
@MCSH
Copy link

MCSH commented Nov 26, 2018

Hello,

I already brought this up in slack. I wanted a way to list all attributes for a given entity, the solution was running the following query:

match person has $x; get;

However, running that will produce

>>> match person has $x; get $x;
'has' argument '$x' requires a label
@sorsaffari

This comment has been minimized.

Copy link
Member

sorsaffari commented Nov 26, 2018

Thanks @MCSH for reporting this :)

@sorsaffari

This comment has been minimized.

Copy link
Member

sorsaffari commented Nov 26, 2018

@kasper-piskorski This is a use case that should be included in our docs. Do you think it could make it to 1.5?

@kasper-piskorski kasper-piskorski added feature bug and removed bug labels Nov 26, 2018

@kasper-piskorski

This comment has been minimized.

Copy link
Member

kasper-piskorski commented Nov 28, 2018

It's a currently unsupported feature. At the moment you can have:

$var has ($v | predicate) - fetch instances with attribute of specific type (and satisfying predicate)
$var has - fetch types that can have a specific attribute

Unlikely to be included in the 1.5.

@sorsaffari

This comment has been minimized.

Copy link
Member

sorsaffari commented Nov 29, 2018

@MCSH here is how you'd do this with the client Python:

  client = grakn.Grakn(uri = "localhost:48555")
  with client.session(keyspace = "phone_calls") as ses:
    with ses.transaction(grakn.TxType.READ) as transaction:
        answer_iterator = transaction.query("match $x sub person; get;")

        for answer in answer_iterator:
          attr_iterator = answer.map().get("x").attributes()

          for attr in attr_iterator:
            print(attr.label())
@sorsaffari

This comment has been minimized.

Copy link
Member

sorsaffari commented Nov 29, 2018

@MCSH similarly with the client Node.js:

async function printAttributesOfPerson() {
  const grakn = new Grakn("localhost:48555");
  const session = await grakn.session((keyspace = "phone_calls"));
  const transaction = await session.transaction(Grakn.txType.READ);

  let answerIterator = await transaction.query("match $x sub person; get;");

  let answer = await answerIterator.next();
  while (answer != null) {
    attrIterator = await answer.map().get("x").attributes();

    let attr = await attrIterator.next();
    while (attr != null) {
      console.log(await attr.label());
      attr = await attrIterator.next();
    }
    answer = await answerIterator.next();
  }

  transaction.close();
  session.close();
}
@MCSH

This comment has been minimized.

Copy link

MCSH commented Nov 29, 2018

Thank you so much.

@sorsaffari

This comment has been minimized.

Copy link
Member

sorsaffari commented Nov 29, 2018

You're most welcome 🙂

@sorsaffari sorsaffari changed the title Getting all attributes of an entity Retrieving all attribute types owned by a concept type Dec 26, 2018

@haikalpribadi haikalpribadi added bug and removed feature labels Jan 15, 2019

@haikalpribadi haikalpribadi added this to the v1.6 milestone Jan 15, 2019

@grabl grabl added the v1.6 label Jan 15, 2019

haikalpribadi added a commit to haikalpribadi/grakn that referenced this issue Jan 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment