Skip to content

LNEx API

Hussein Al-Olimat edited this page Mar 21, 2019 · 3 revisions

LNEx can also be used as a service through its RESTful API.

Python Utility

Following is an example code you can use to query the API and tag your texts to find locations in them.

from LNExAPI import LNExAPI

# how to parse the data returned
def displayResults(results):
  for result in results:
    print("Matches for:",result['text'])
    for entity in result['entities']:
      print("[ ]-->",entity['match'])
      for location in entity['locations']:
        print("   [ ]-->",str(location['coordinate']['lat'])+","+str(location['coordinate']['lon']))

lnex = LNExAPI("APIKEY",host="http://130.108.86.152/apiv1/LNEx/")
lnex.initZone([-84.6447033333,39.1912856591,-83.2384533333,40.0880515857],"dayton")

print("waiting for zone to init...")
lnex.pollZoneReady("dayton")

text=[
    "Have you seen the kettering towers?",
    "You should check out 3rd street",
    "meet me over at wright state university",
    "head over to the Mudlick Tap House on 2nd street, it's close to Miami River",
    "I'm heading to Table 33, they got good food in dayton",
    "Have you tried Spend Grain Grill? It's better than Olive Garden",
    "I can meet you at Watervliet Ave.",
    "I've never been to the Dayton Mall",
    "Anybody know where the Sears building is?",
    "I'm looking to get to the library",
    "Wright State University is a great school",
    "Brown Street is where good food is, next to the UD campus",
    "Wright Brothers parkway is also known as Woodman Drive",
    "I live right next to the Dayton Library",
    "The Wingate hotel is just outside my window",
    "I'm looking for China One"]

result_token,results=lnex.pollFullBulkExtract("dayton",text)

displayResults(results)

You need to install the following Python3 wheel: https://link.hussein.space/LNExAPIwhl

API Key:

Make sure you have a valid API key, which you can request from here.

Bash Utility

You can also use LNEx in bash scripts using the following commands:

curl -g -XGET "http://130.108.86.152/apiv1/LNEx/initZone?bb=[-84.7111,39.3913,-83.5856,40.1377]&zone=dayton&user=test&key=APIKEY"
curl -XPOST -d @lnexBulkTest.json -H'Content-Type: application/json' "http://130.108.86.152/apiv1/LNEx/bulkExtract?zone=dayton&user=test&key=APIKEY"

Where, lnexBulkTest.json is:

{
  "data": [
    "I want to go to University of Dayton",
    "I want to go to Wright State University near Colonel Glenn Highway"
  ]
}

To finally get your results, you should plug in the result token in the following command:

curl -g -XGET "http://130.108.86.152/apiv1/LNEx/results?user=test&key=APIKEY&token=USERESULTTOKENHERE"
Clone this wiki locally