apache-age-python icon indicating copy to clipboard operation
apache-age-python copied to clipboard

Nodes not printing, error: line 1:100 missing '::path' at '<EOF>'

Open afidegnum opened this issue 4 years ago • 10 comments

apache-age-python returns an error over result formatting. from the AGEviewerer, this query successfully prints the results as right-left nodes containing the list of the right nodes as shown below:

          SELECT * from cypher('text_test', $$
          MATCH (V:node)-[connect]->(V2:node)
			WITH V as parent, COLLECT(V2) as children
          RETURN parent, children
$$) as (parent agtype, children agtype);

and the result below:

{"id":844424930131987,"label":"node","properties":{"tag":"div","attrib":"{\"id\": \"second\", \"class\": \"below\"}"}}	[{"id":844424930131988,"label":"node","properties":{"tag":"div","attrib":"{\"class\": \"inner\"}"}}]

{"id":844424930131973,"label":"node","properties":{"tag":"body","attrib":"null"}}	
[{"id":844424930131987,"label":"node","properties":{"tag":"div","attrib":"{\"id\": \"second\", \"class\": \"below\"}"}},{"id":844424930131978,"label":"node","properties":{"tag":"div","attrib":"{\"id\": \"idone\", \"class\": \"classone\"}"}},{"id":844424930131974,"label":"node","properties":{"tag":"ul","attrib":"{\"class\": \"menu\"}"}}]

{"id":844424930131970,"label":"node","properties":{"tag":"head","attrib":"null"}}	
[{"id":844424930131972,"label":"node","properties":{"tag":"title","attrib":"null"}},
{"id":844424930131971,"label":"node","properties":{"tag":"meta","attrib":"{\"charset\": \"UTF-8\"}"}}]

{"id":844424930131985,"label":"node","properties":{"tag":"div","attrib":"{\"id\": \"innertwo\"}"}}	[{"id":844424930131986,"label":"node","properties":{"tag":"h2","attrib":"null"}}]

{"id":844424930131978,"label":"node","properties":{"tag":"div","attrib":"{\"id\": \"idone\", \"class\": \"classone\"}"}}
	
[{"id":844424930131985,"label":"node","properties":{"tag":"div","attrib":"{\"id\": \"innertwo\"}"}},{"id":844424930131983,"label":"node","properties":{"tag":"div","attrib":"{\"id\": \"innerone\"}"}},{"id":844424930131979,"label":"node","properties":{"tag":"ul","attrib":"{\"class\": \"listing\"}"}}]

{"id":844424930131974,"label":"node","properties":{"tag":"ul","attrib":"{\"class\": \"menu\"}"}}
	[{"id":844424930131977,"label":"node","properties":{"tag":"div","attrib":"{\"class\": \"itm\"}"}},{"id":844424930131976,"label":"node","properties":{"tag":"div","attrib":"{\"class\": \"itm\"}"}},{"id":844424930131975,"label":"node","properties":{"tag":"div","attrib":"{\"class\": \"itm\"}"}}]

{"id":844424930131988,"label":"node","properties":{"tag":"div","attrib":"{\"class\": \"inner\"}"}}	
[{"id":844424930131991,"label":"node","properties":{"tag":"h2","attrib":"null"}},{"id":844424930131990,"label":"node","properties":{"tag":"h1","attrib":"null"}},{"id":844424930131989,"label":"node","properties":{"tag":"h1","attrib":"null"}}]

{"id":844424930131983,"label":"node","properties":{"tag":"div","attrib":"{\"id\": \"innerone\"}"}}	[{"id":844424930131984,"label":"node","properties":{"tag":"h1","attrib":"null"}}]

{"id":844424930131979,"label":"node","properties":{"tag":"ul","attrib":"{\"class\": \"listing\"}"}}	[{"id":844424930131982,"label":"node","properties":{"tag":"li","attrib":"{\"class\": \"item3\"}"}},
{"id":844424930131981,"label":"node","properties":{"tag":"li","attrib":"{\"class\": \"item2\"}"}},{"id":844424930131980,"label":"node","properties":{"tag":"li","attrib":"{\"class\": \"item1\"}"}}]

{"id":844424930131969,"label":"node","properties":{"tag":"html","attrib":"{\"lang\": \"en\"}"}}	[{"id":844424930131973,"label":"node","properties":{"tag":"body","attrib":"null"}},{"id":844424930131970,"label":"node","properties":{"tag":"head","attrib":"null"}}]

while using the same procedure on apache-python-age, here is the resulting output.

import psycopg2 
import age

GRAPH_NAME = "text_test"
DSN = "host=localhost port=5432 dbname=texttest user=afidegnum password=chou1979"
conn = psycopg2.connect(DSN)

age.setUpAge(conn, GRAPH_NAME)

def get_tree(n_id):
    """ Get the trees"""
    with conn.cursor() as cursor:
        try :                    
            cursor.execute("""
            SELECT * from cypher(%s, $$
            MATCH (V:node)-[r:connect]->(V2:node)
			WITH r as nodes,  COLLECT(V2) as children
          RETURN nodes, children
$$) as (nodes agtype, children agtype);
            """, (GRAPH_NAME,))
        
            for row in cursor:
                print(row)
                            
        except Exception as ex:
            print(ex)
            conn.rollback()


node_id = 844424930131969
                                      
get_tree(node_id)

here is the result obtained:

__init__() missing 1 required positional argument: 'cause'
line 1:189 mismatched input '::vertex' expecting '::edge'
line 1:408 mismatched input '::vertex' expecting '::edge'
line 1:682 mismatched input '::vertex' expecting '::edge'
line 1:910 mismatched input '::vertex' expecting '::edge'
line 1:1138 mismatched input '::vertex' expecting '::edge'
line 1:1370 mismatched input '::vertex' expecting '::edge'
line 1:1602 mismatched input '::vertex' expecting '::edge'
line 1:1832 mismatched input '::vertex' expecting '::edge'
line 1:2026 mismatched input '::vertex' expecting '::edge'
line 1:2239 mismatched input '::vertex' expecting '::edge'
line 1:2433 mismatched input '::vertex' expecting '::edge'

Care to look into it ?

afidegnum avatar Dec 05 '21 13:12 afidegnum

The same applies to this:

import age
from age.gen.ageParser import *
GRAPH_NAME = "text_test"

DSN = "host=localhost port=5432 dbname=texttest user=afidegnum password=demo001"
ag = age.connect(graph=GRAPH_NAME, dsn=DSN)

def graph_one():
    children = ag.execCypher("MATCH (V:node)-[connect]->(V2:node) WITH V as parent, COLLECT(V2) as children RETURN {parent: parent, children: children}")
    for c in children:
        print(c)
        #graph_nodes(c[0].id)

and the result obtained:

(None,)
(None,)
(None,)
(None,)
(None,)
(None,)
(None,)
(None,)
(None,)
(None,)
line 1:137 no viable alternative at input '{"parent":{"id":844424930131987,"label":"node","properties":{"tag":"div","attrib":"{\"id\": \"second\", \"class\": \"below\"}"}}::vertex'
line 1:100 no viable alternative at input '{"parent":{"id":844424930131973,"label":"node","properties":{"tag":"body","attrib":"null"}}::vertex'
line 1:100 no viable alternative at input '{"parent":{"id":844424930131970,"label":"node","properties":{"tag":"head","attrib":"null"}}::vertex'
line 1:117 no viable alternative at input '{"parent":{"id":844424930131985,"label":"node","properties":{"tag":"div","attrib":"{\"id\": \"innertwo\"}"}}::vertex'
line 1:139 no viable alternative at input '{"parent":{"id":844424930131978,"label":"node","properties":{"tag":"div","attrib":"{\"id\": \"idone\", \"class\": \"classone\"}"}}::vertex'
line 1:115 no viable alternative at input '{"parent":{"id":844424930131974,"label":"node","properties":{"tag":"ul","attrib":"{\"class\": \"menu\"}"}}::vertex'
line 1:117 no viable alternative at input '{"parent":{"id":844424930131988,"label":"node","properties":{"tag":"div","attrib":"{\"class\": \"inner\"}"}}::vertex'
line 1:117 no viable alternative at input '{"parent":{"id":844424930131983,"label":"node","properties":{"tag":"div","attrib":"{\"id\": \"innerone\"}"}}::vertex'
line 1:118 no viable alternative at input '{"parent":{"id":844424930131979,"label":"node","properties":{"tag":"ul","attrib":"{\"class\": \"listing\"}"}}::vertex'
line 1:114 no viable alternative at input '{"parent":{"id":844424930131969,"label":"node","properties":{"tag":"html","attrib":"{\"lang\": \"en\"}"}}::vertex'

afidegnum avatar Dec 06 '21 10:12 afidegnum

you can have a look at my notebook

afidegnum avatar Dec 06 '21 20:12 afidegnum

AGE is upgraded. So some cypher specs were added. I will fix soon.

rhizome-ai avatar Dec 07 '21 14:12 rhizome-ai

Thanks

afidegnum avatar Dec 07 '21 16:12 afidegnum

I've just update version v0.0.4. Please pull repository again.

rhizome-ai avatar Dec 09 '21 04:12 rhizome-ai

Thanks a lot, let me try it again

afidegnum avatar Dec 09 '21 06:12 afidegnum

is age.gen.ageParser no more available on the new version?

afidegnum avatar Dec 09 '21 07:12 afidegnum

the following errors were encoutered:

###################

import age
# from age.gen.ageParser import *
GRAPH_NAME = "text_test"
DSN = "host=localhost port=5432 dbname=texttest user=demousr password=demo123"

#-----------------------------------------------------------------------

NoneType                                 Traceback (most recent call last)
/tmp/ipykernel_4572/1308679823.py in <module>
----> 1 ag = age.connect(graph=GRAPH_NAME, dsn=DSN)
      2 ag.setGraph(GRAPH_NAME)

~/.virtualenvs/orgs/lib/python3.9/site-packages/age/__init__.py in connect(dsn, graph, connection_factory, cursor_factory, **kwargs)
     25 def connect(dsn=None, graph=None, connection_factory=None, cursor_factory=None, **kwargs):
     26         ag = Age()
---> 27         ag.connect(dsn=dsn, graph=graph, connection_factory=connection_factory, cursor_factory=cursor_factory, **kwargs)
     28         return ag
     29 

~/.virtualenvs/orgs/lib/python3.9/site-packages/age/age.py in connect(self, graph, dsn, connection_factory, cursor_factory, **kwargs)
    150     def connect(self, graph:str=None, dsn:str=None, connection_factory=None, cursor_factory=None, **kwargs):
    151         conn = psycopg2.connect(dsn, connection_factory, cursor_factory, **kwargs)
--> 152         setUpAge(conn, graph)
    153         self.connection = conn
    154         self.graphName = graph

~/.virtualenvs/orgs/lib/python3.9/site-packages/age/age.py in setUpAge(conn, graphName)
     32 
     33         cursor.execute("SELECT typelem FROM pg_type WHERE typname='_agtype'")
---> 34         oid = cursor.fetchone()[0]
     35         if oid == None :
     36             raise AgeNotSet()

TypeError: 'NoneType' object is not subscriptable

afidegnum avatar Dec 09 '21 07:12 afidegnum

Yes, type parser name(age.gen.ageParser) was changed to age.gen.AgtypeParser .

And previous error, it seems like that AGE extension is not loaded( 'LOAD AGE' ) on age DB.

Please check.

rhizome-ai avatar Dec 09 '21 07:12 rhizome-ai

everything is ok now

afidegnum avatar Dec 09 '21 07:12 afidegnum