Exemple #1
0
 def search(self, prenom_nom):
     """
     Search all nodes which attribute `prenomnom` matches the query
         :param prenom_nom: the text query
     """
     tokens = prenom_nom.strip().split()
     str_query = es_fuzzy_string_query(tokens)
     # Use JanusGraph direct index query
     # https://docs.janusgraph.org/latest/direct-index-query.html
     query = "graph.indexQuery('vertexByPrenomNom', 'v.prenomnom:%s')\
         .limit(10).vertices()" % str_query
     client = self.connection._client
     vertices_and_score = client.submit(query).all().result()
     vertices = [v["element"] for v in vertices_and_score]
     search_results = []
     if vertices:
         # find all the matching vertices
         traversal = self.g.V(vertices)
         # add the attribute `degree` on each vertex
         traversal = traversal.property('degree', __.both().dedup().count())
         # select attributes
         traversal = traversal \
             .project(
                 'entity',
                 'prenom_nom',
                 'prenom',
                 'nom',
                 'code_postal',
                 'pays_code',
                 'numero_piece_identite',
                 'degree') \
             .by('entity') \
             .by('prenomnom') \
             .by('prenom') \
             .by('nom') \
             .by('code_postal') \
             .by('pays_code') \
             .by('numero_piece_identite') \
             .by('degree')
         search_results.extend(traversal.toList())
     return search_results
Exemple #2
0
from gremlin_python.process.traversal import P
from gremlin_python.process.traversal import Pop
from gremlin_python.process.traversal import Scope
from gremlin_python.process.traversal import Barrier
from gremlin_python.process.traversal import Bindings
from gremlin_python.process.traversal import WithOptions

statics.load_statics(globals())

# for direct calls
g = traversal().withRemote(
    DriverRemoteConnection('ws://134.158.74.85:24444/gremlin', 'g'))

# for submitting scripts
client = client.Client('ws://134.158.74.85:24444/gremlin', 'g')

x = g.V().has('lbl', 'alert').limit(1).valueMap().next()
print(x)

x = g.V().has('lbl', 'candidate').has('jd', inside(
    2459324.90447, 2459324.90448)).in_().values('objectId').next()
print(x)

query = "g.V().has('lbl', 'alert').limit(1).valueMap()"
x = client.submit(query).next()
print(x)

query = "g.V().has('lbl', 'candidate').has('direction', geoWithin(Geoshape.circle(5.475797, -87.662704, 0.00001*6371.0087714*180/Math.PI))).valueMap()"
x = client.submit(query).one()[0].get('direction')[0].get('@value')
print(x)
Exemple #3
0
from gremlin_python.driver import client
client = client.Client('ws://10.15.14.209:8182/gremlin', 'g')

result_set = client.submit("[1,2,3,4]")
future_results = result_set.all()
results = future_results.result()
assert results == [1, 2, 3, 4]

future_result_set = client.submitAsync("[1,2,3,4]")
result_set = future_result_set.result()
result = result_set.one()
assert results == [1, 2, 3, 4]
assert result_set.done.done()

client.close()
Exemple #4
0
#
# This example code assumes that the GremlinPython library has been installed using:
#
#     pip install gremlinpython
#

# Import some classes we will need to talk to our graph
from gremlin_python.driver import client

# Path to our graph (this assumes a locally running Gremlin Server)
# Note how the path is a Web Socket (ws) connection.
client = client.Client('ws://localhost:8182/gremlin', 'g')

query = """
g.V().hasLabel('airport').
               sample(30).
               order().by('code').
               local(__.values('code','city').fold()).
               toList()
"""

result = client.submit(query)
future_results = result.all()
results = future_results.result()

client.close()

# Print the results in a tabular form with a row index
for i, c in enumerate(results, 1):
    print("%3d %4s %s" % (i, c[0], c[1]))