usc-isi-i2 / kgtk

Knowledge Graph Toolkit

Home Page:https://kgtk.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help with: Defining and using custom functions

versant2612 opened this issue · comments

Describe the bug
I want to manipulate geometry data of node2 from my kgtk file using pygeos (python library)

To Reproduce

  1. pygeos instalation
  2. data definition
    CKG-H4-geo.txt
  3. query

export GRAPH_CKG_GEO=/app/kgtk/data/H4/CKG-H4-geo.tsv

A)
\time --format='Elapsed time: %e seconds' kgtk --debug query -i $GRAPH_CKG_GEO --as geo --force --import 'pygeos as pg'
--match 'geo: (:h4v9)-[r1:h4r2]->(v1), (y)-[r2:h4r2]->(v2) '
--where 'y != "h4v9"'
--return '"h4v9" as node1, y as node2, v1, v2, pycall("pg.Geometry", v1) as geo1, pycall("pg.Geometry", v2) as geo2, pycall("pg.intersects", geo1, geo2) as hasIntersection'
-o /app/kgtk/data/H4/CKG-H4-K7-geo.tsv

B)
\time --format='Elapsed time: %e seconds' kgtk --debug query -i $GRAPH_CKG_GEO --as geo --force --import 'pygeos as pg'
--match 'geo: (:h4v9)-[r1:h4r2]->(v1), (y)-[r2:h4r2]->(v2) '
--where 'y != "h4v9"'
--return '"h4v9" as node1, y as node2, pycall("pg.intersection", v1, v2) as hasIntersection'
-o /app/kgtk/data/H4/CKG-H4-K7-geo.tsv

Expected behavior
Return True or False from the pg.intersects function but it returns no values. Or at least return intersection points from pg.intersection function.

CKG-H4-K7-geo.txt

I created a function in python that receives two strings, turns them into geometry, checks the intersection, returns True or False as a string but I am also not getting the kgtk query to recognize.

kgtk --debug query -i $GRAPH_CKG_GEO --as geo --force --import 'geo_functions.py' --match 'geo: (:h4v9)-[r1:h4r2]->(v1), (y)-[r2:h4r2]->(v2) ' --where 'y != "h4v9"' --return '"h4v9" as node1, y as node2, pycall("geo_intersection", v1, v2) as hasIntersection'

Traceback (most recent call last):
  File "/app/kgtk/miniconda3/bin/kgtk", line 8, in
    sys.exit(cli_entry())
  File "/app/kgtk/miniconda3/lib/python3.9/site-packages/kgtk/cli_entry.py", line 478, in cli_entry
    subp = mod.parser()
AttributeError: module 'kgtk.cli.geo_functions' has no attribute 'parser'
Command exited with non-zero status 1
Elapsed time: 0.69 seconds