|
|
|
@ -1,19 +1,17 @@
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Mongodb storage init
|
|
|
|
Mongodb storage init
|
|
|
|
|
|
|
|
|
|
|
|
- collections creation
|
|
|
|
- collections queries initialization
|
|
|
|
- helper queries
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TODO : maybe put the mongodb connector into the flask app object
|
|
|
|
TODO : maybe put the mongodb connector into the flask app object
|
|
|
|
with the pymongo library.
|
|
|
|
with the pymongo library.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
import urllib.parse
|
|
|
|
import urllib.parse
|
|
|
|
|
|
|
|
|
|
|
|
from unidecode import unidecode # to remove accents in house and prince names in the urls
|
|
|
|
|
|
|
|
from pymongo import MongoClient
|
|
|
|
from pymongo import MongoClient
|
|
|
|
|
|
|
|
|
|
|
|
from .config import dbadmin, dbpassword, server_ip
|
|
|
|
from .config import dbadmin, dbpassword, server_ip
|
|
|
|
|
|
|
|
from .helper import normalize_trigrams
|
|
|
|
|
|
|
|
|
|
|
|
# ______________________________________________________________________________
|
|
|
|
# ______________________________________________________________________________
|
|
|
|
# database connexion
|
|
|
|
# database connexion
|
|
|
|
@ -37,6 +35,11 @@ helpers = actesdb["helpers"]
|
|
|
|
# ______________________________________________________________________________
|
|
|
|
# ______________________________________________________________________________
|
|
|
|
# storage extractor utilities
|
|
|
|
# storage extractor utilities
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_acteid_from_route(house=None, prince=None, date_and_item=None):
|
|
|
|
|
|
|
|
"/acte/Anjou/Isabelle_i/1441_08_05a -> anj_isa_i_1441_08_05a"
|
|
|
|
|
|
|
|
return "_".join([trigram_house(house), bigram_prince(prince), date_and_item])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def extract_princes_in_houses():
|
|
|
|
def extract_princes_in_houses():
|
|
|
|
"""Extracts all princes from a house
|
|
|
|
"""Extracts all princes from a house
|
|
|
|
by queries in the storage, (not by using csv metadatas)
|
|
|
|
by queries in the storage, (not by using csv metadatas)
|
|
|
|
@ -70,14 +73,6 @@ def extract_prince_in_house(house, prince_code):
|
|
|
|
return pr
|
|
|
|
return pr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def normalize_trigrams(trigram):
|
|
|
|
|
|
|
|
"""normalizes names, usefull for the uris routes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sample: Alençon -> Alencon
|
|
|
|
|
|
|
|
Orléans -> Orleans
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
return {unidecode(value):key for key, value in trigram.items()}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ______________________________________________________________________________
|
|
|
|
# ______________________________________________________________________________
|
|
|
|
# in memory storage extracted 'meta' informations upon the database
|
|
|
|
# in memory storage extracted 'meta' informations upon the database
|
|
|
|
# TODO: if it takes too much time at launch, put it in something like
|
|
|
|
# TODO: if it takes too much time at launch, put it in something like
|
|
|
|
@ -99,3 +94,23 @@ prince_bigram sample:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
prince_bigram = normalize_trigrams(prince_bigram)
|
|
|
|
prince_bigram = normalize_trigrams(prince_bigram)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def inverted_prince_bigram(bigram):
|
|
|
|
|
|
|
|
"Translates ch -> Charles"
|
|
|
|
|
|
|
|
inverted_prince_bigram = {value: key for key, value in prince_bigram.items()}
|
|
|
|
|
|
|
|
return inverted_prince_bigram[bigram]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def bigram_prince(prince):
|
|
|
|
|
|
|
|
"Translates Charles_i -> ch_i"
|
|
|
|
|
|
|
|
name, number = prince.split("_")
|
|
|
|
|
|
|
|
return prince_bigram[name] + "_" + number
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def trigram_house(house):
|
|
|
|
|
|
|
|
return house_trigram[house]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|