Commit c45f6dee authored by Christine Plumejeaud's avatar Christine Plumejeaud
Browse files

Changed the way to handle link (getlinks): always return an empty string.

describePlace : a new method to factor code.
database version : portic_v5, port 5433 from now. Was tested as locally. Must be deployed in prod.
Minor fixes.
parent 98d525ca
......@@ -36,8 +36,8 @@ CORS(app)
port = '80'
postgresport = '5432'
database = 'portic_v4'
postgresport = '5433'
database = 'portic_v5'
names = dict()
names['Corse'] = 'Isles de Corse'
......@@ -59,6 +59,8 @@ def retrieveDataFromPostgres(query) :
import pandas as pd
#connection = pg.connect("host='134.158.33.179' port='5433' dbname='portic_v3' user='api_user' password='portic'")
connection = pg.connect("""host='localhost' port='%s' dbname='%s' user='api_user' password='portic'"""% (postgresport, database))
#connection = pg.connect("host='localhost' port='8004' dbname='portic_v5' user='api_user' password='portic'")
#ssh -N -L 8004:localhost:5433 -v navigo@134.158.33.179
df = pd.read_sql_query(query,con=connection)
connection.close()
......@@ -210,50 +212,16 @@ def getPorts():
print (srid)
query = """SELECT ogc_fid, uhgs_id, total, toponyme as toponym, belonging_states, status, geonameid, amiraute as admiralty, province, shiparea , ST_AsGeoJSON(ST_Transform(geom, %s)) as point
query = """SELECT ogc_fid, uhgs_id, total, toponyme as toponym, belonging_states, belonging_substates, status, geonameid, amiraute as admiralty, province, shiparea , ST_AsGeoJSON(ST_Transform(geom, %s)) as point
FROM ports.port_points p,
(select pointcall_uhgs_id, count( *) as total
(select pointcall_uhgs_id, count(*) as total
from navigoviz.pointcall gg group by pointcall_uhgs_id) as k
where p.toponyme is not null and p.uhgs_id = k.pointcall_uhgs_id""" %(srid)
data = retrieveDataFromPostgres(query)
return formatOutput(data, 'ports')
@app.route('/places/')
def getPlaces():
"""
Return the places using linked places model as specified in
https://github.com/LinkedPasts/linked-places
See : http://linkedpasts.org/ontology/lpo_latest.ttl
Will be extracted from postgres, schema navigoviz, table ports.port_points (see navigocorpus/ETL)
http://127.0.0.1:80/places/?Dunkerque
http://127.0.0.1:80/places/?A0198999
http://127.0.0.1:80/places/?Flandre
"""
kind_of_entity = 'port'
dico = request.args.to_dict()
for k in dico.keys():
#print('search for '+k)
#Check that this one exists in the database (case sensitive)
query = """select uhgs_id, toponyme, amiraute, province from ports.port_points"""
results = retrieveDataFromPostgres(query)
if k in results['uhgs_id'].tolist() :
kind_of_entity = 'port'
elif k in results['amiraute'].tolist() :
kind_of_entity = 'amiraute'
elif k in results['province'].tolist() :
kind_of_entity = 'province'
else :
#We stop here
return '{ "No entry like this :" '+k+'}'
def describePlace(kind_of_entity, identifier):
# Read the template_feature
template = os.path.join(APP_ROOT, 'template_feature.json')
test = os.path.join(APP_ROOT, 'test.json')
......@@ -269,7 +237,7 @@ def getPlaces():
#param_uhgs_id = 'A0222919' # Isles de Saint Pierre
#param_uhgs_id = 'A0115898' # Mahon
#param_uhgs_id = 'A0198999' #La Rochelle
param_uhgs_id = k
param_uhgs_id = identifier
if kind_of_entity == 'port' :
## Read data about the entity port
......@@ -284,6 +252,10 @@ def getPlaces():
ccodes = 'FR'
toponym = param_uhgs_id
## When
start='1749'
end='1815'
## Les noms
if kind_of_entity == 'port':
names = getPortNames(toponym, param_uhgs_id)
......@@ -313,16 +285,55 @@ def getPlaces():
relations = getProvinceRelation()
## Fill template with description
description = template_description % (param_uhgs_id, title, ccodes, names[:-1], types, geometries, links, relations)
description = template_description % (param_uhgs_id, title, ccodes, start, end, names[:-1], types, geometries, links, relations)
'''
output = open(test, "w") #"utf-8"
output.write( description) #json.dumps(description)
output.close()
'''
return description
#return json.loads(description)
@app.route('/places/')
def getPlaces():
"""
Return the places using linked places model as specified in
https://github.com/LinkedPasts/linked-places
See : http://linkedpasts.org/ontology/lpo_latest.ttl
Will be extracted from postgres, schema navigoviz, table ports.port_points (see navigocorpus/ETL)
http://127.0.0.1:80/places/?Dunkerque
http://127.0.0.1:80/places/?A0198999
http://127.0.0.1:80/places/?Flandre
"""
kind_of_entity = 'port'
dico = request.args.to_dict()
for k in dico.keys():
#print('search for '+k)
#Check that this one exists in the database (case sensitive)
query = """select uhgs_id, toponyme, amiraute, province from ports.port_points"""
results = retrieveDataFromPostgres(query)
if k in results['uhgs_id'].tolist() :
kind_of_entity = 'port'
elif k in results['amiraute'].tolist() :
kind_of_entity = 'amiraute'
elif k in results['province'].tolist() :
kind_of_entity = 'province'
else :
#We stop here
return '{ "No entry like this :" '+k+'}'
return describePlace(kind_of_entity, k)
def getPortGeometry(uhgs_id, longitude, latitude, geonameid = None):
"""
Internal method to get port geometries : Point of geo_general plus Point from geonames if a match exists with
......@@ -393,8 +404,8 @@ def getProvinceGeometry(toponyme) :
ports = retrieveDataFromPostgres(query)
geometries = ''
for uhgs_id in ports['uhgs_id'] :
print((ports.loc[ports['uhgs_id'] == uhgs_id, 'longitude'].values[0]))
print(ports.loc[ports['uhgs_id'] == uhgs_id, 'latitude'].values[0])
#print((ports.loc[ports['uhgs_id'] == uhgs_id, 'longitude'].values[0]))
#print(ports.loc[ports['uhgs_id'] == uhgs_id, 'latitude'].values[0])
geometries = geometries + getPortGeometry(uhgs_id, ports.loc[ports['uhgs_id'] == uhgs_id, 'longitude'].values[0], ports.loc[ports['uhgs_id'] == uhgs_id, 'latitude'].values[0]) + ','
return geometries[:-1]
......@@ -482,14 +493,18 @@ def getLinks(uhgs_id, type = 'port') :
wiki_provinces['Flandre'] = 'https://fr.wikipedia.org/wiki/Flandre_fran%C3%A7aise'
wiki_provinces['Corse'] = 'https://fr.wikipedia.org/wiki/Corse_(province)'
links = ""
if type == 'port':
query = """select id2, simtext, distgeo, certainity from ports.matching_port
where source1 = 'geo_general' and source2='geonames' and uhgs_id ='%s' and best is true""" %(uhgs_id)
matches = retrieveDataFromPostgres(query)
#print(" nombre de links %d pour le port %s " %(matches.shape[0], uhgs_id))
if (matches.shape[0]> 0) :
link_type = 'exactMatch'
if (matches.shape[0]> 1) :
link_type = 'closeMatch'
links = """{"type": "%s", "identifier": "http://www.geonames.org/%s/"}""" % (link_type, matches.loc[0, 'id2'])
#print(links)
if type == 'amiraute' :
links = """{"type": "primaryTopicOf", "identifier": "https://fr.wikipedia.org/wiki/Amiraut%C3%A9_(justice)"} """
......@@ -497,12 +512,16 @@ def getLinks(uhgs_id, type = 'port') :
if type == 'province' :
links = """{"type": "primaryTopicOf", "identifier": "https://fr.wikipedia.org/wiki/Territoires_du_royaume_de_France"}"""
links = links +""", {"type": "primaryTopicOf", "identifier": "https://fr.wikipedia.org/wiki/Territoires_du_royaume_de_France#Liste_des_anciennes_provinces_de_France"}"""
if uhgs_id in wiki_provinces.keys():
links = links +""", {"type": "primaryTopicOf", "identifier": "%s"} """% (wiki_provinces[uhgs_id])
else :
print('no entry in wiki_provinces for '+uhgs_id)
if uhgs_id == 'Bretagne' :
links = links +""", {"type": "subjectOf", "identifier": "https://fr.wikipedia.org/wiki/Amiraut%C3%A9s_de_Bretagne"} """
if uhgs_id == 'Guyenne' :
links = links +""", {"type": "subjectOf", "identifier": "https://fr.wikipedia.org/wiki/Amiraut%C3%A9_de_Guyenne"}"""
return links
......@@ -574,7 +593,7 @@ def getPortRelations(uhgs_id) :
},""" % (state.loc[0, 'amiraute'], state.loc[0, 'amiraute'])
# Si il a une province :
if state.loc[0, 'amiraute'] is not None:
if state.loc[0, 'province'] is not None:
relations = relations + """
{ "relationType": "gvp:broaderPartitive",
"relationTo": "http://gaz.portic.fr/places/?%s",
......@@ -647,4 +666,7 @@ def getProvinceRelation() :
if __name__ == '__main__':
app.run(debug=True,port=port,threaded=True)
#describePlace('port', 'A0198999')
#saveGazetteer()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment