Skip to content
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

Match nodes by label #8

Open
spranger opened this issue May 2, 2024 · 4 comments
Open

Match nodes by label #8

spranger opened this issue May 2, 2024 · 4 comments

Comments

@spranger
Copy link

spranger commented May 2, 2024

Is their a way to match nodes by labels. eg. MATCH (p:Person) RETURN p.name?

@j6k4m8
Copy link
Member

j6k4m8 commented May 2, 2024

@spranger: Yes!

import networkx as nx
from grandcypher import GrandCypher

host = nx.DiGraph()
host.add_edge("spranger", "grandlite")
host.add_node("spranger", __labels__={"Person"})
host.add_node("grandlite", __labels__={"Repository"})

GrandCypher(host).run("MATCH (n:Person) RETURN n")

See aplbrain/grand-cypher#22 for more details :)

@spranger
Copy link
Author

spranger commented May 3, 2024

Thanks a lot.
But I meant using a .graphml-file with grandlite, where the nodes have various attributes, including a type or a label

Regards
Steffen

@spranger
Copy link
Author

spranger commented May 3, 2024

the cypher ""MATCH (n:Person) RETURN n"" query fails:

    result = GrandCypher(host).run("MATCH (n:Person) RETURN n")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\SSR\PycharmProjects\simple_graph_sqlite_example\.venv3\Lib\site-packages\grandcypher\__init__.py", line 466, in run
    self._transformer.transform(_GrandCypherGrammar.parse(cypher))
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\SSR\PycharmProjects\simple_graph_sqlite_example\.venv3\Lib\site-packages\lark\lark.py", line 581, in parse
    return self.parser.parse(text, start=start, on_error=on_error)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\SSR\PycharmProjects\simple_graph_sqlite_example\.venv3\Lib\site-packages\lark\parser_frontends.py", line 106, in parse
    return self.parser.parse(stream, chosen_start, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\SSR\PycharmProjects\simple_graph_sqlite_example\.venv3\Lib\site-packages\lark\parsers\earley.py", line 297, in parse
    to_scan = self._parse(lexer, columns, to_scan, start_symbol)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\SSR\PycharmProjects\simple_graph_sqlite_example\.venv3\Lib\site-packages\lark\parsers\xearley.py", line 144, in _parse
    to_scan = scan(i, to_scan)
              ^^^^^^^^^^^^^^^^
  File "C:\Users\SSR\PycharmProjects\simple_graph_sqlite_example\.venv3\Lib\site-packages\lark\parsers\xearley.py", line 118, in scan
    raise UnexpectedCharacters(stream, i, text_line, text_column, {item.expect.name for item in to_scan},
lark.exceptions.UnexpectedCharacters: No terminal matches ':' in the current parser context, at line 1 col 9

MATCH (n:Person) RETURN n
        ^
Expected one of: 
	* LBRACE
	* RPAR

my environment:
grand-cypher 0.3.0
grand-graph 0.4.2
grandiso 2.2.0
grandlite 0.1.0

python 3.12.1
windows 10

@j6k4m8
Copy link
Member

j6k4m8 commented May 3, 2024

Try updating grand-cypherwe added support for __labels__ in v0.4.0!

Right now we only support entity labels using the __labels__ "magic" attribute (this is to avoid colliding with users' vertex attributes). So if the GraphML file has __labels__ specified, we'll use them — otherwise you can still use Cypher query clauses to search for other attributes. If you're populating the type attribute on your nodes, for example, you could do this:

MATCH (n) 
WHERE n.type = "Person"
RETURN n

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants