# Path: ppp_questionparsing_grammatical/nounDB.py
# class TextStream:
# class Nounificator:
#     def __init__(self, directSymbol = ' -> ', inverseSymbol = ' <- ', separator = ', '):
#     def load(self, f):
#     def dump(self, data, f):
#     def __init__(self):
#     def select(self, x):
#     def __str__(self):
#     def __eq__(self, other):
#     def load(self, fileName):
#     def save(self, fileName):
#     def _add(self, verb, noun, target):
#     def addDirect(self, verb, noun):
#     def addInverse(self, verb, noun):
#     def addListDirect(self, verb, nounList):
#     def addListInverse(self, verb, nounList):
#     def _remove(self, verb, noun, target):
#     def removeDirect(self, verb, noun):
#     def removeInverse(self, verb, noun):
#     def _removeVerb(self, verb, target):
#     def removeVerbDirect(self, verb):
#     def removeVerbInverse(self, verb):
#     def _toNouns(self, verb, target):
#     def directNouns(self, verb):
#     def inverseNouns(self, verb):
#     def exists(self, verb):
#     def merge(self, other):


import requests
import sys
import os
import time
import pickle
import difflib # string similarity
from conceptnet5.nodes import normalized_concept_name, uri_to_lemmas
from nltk import word_tokenize, pos_tag
from nltk.corpus import wordnet as wn
from ppp_questionparsing_grammatical import nounDB
        cand.processURI()
        cand.posTag()
        return cand
    else:
        return None

def associatedWords(verb, relations):
    """
        Returns the best nb_results candidates to nounify the pattern
    """
    pattern = normalized_concept_name(default_language, verb) # Lemmatization+stemming
    uri = "/c/{0}/{1}".format(default_language, pattern)
    r = requests.get('http://127.0.0.1:8084/data/5.3' + uri, params={'limit':default_lookup_limit}).json()
    res = []
    for e in r['edges']:
        if e['rel'] in relations:
            cand = buildCandidate(pattern, e)
            if cand != None and cand.tag != -1:
                res.append(cand)
    for cand in res:
        cand.computeScore()
    computeWeight(res)
    res.sort(key = lambda x: x.score)
    nb_results = min(len(res), default_number_results)
    return {a.word for a in res[-nb_results:]}

def test(verb):
    return associatedWords(verb, {'/r/RelatedTo', '/r/DerivedFrom', '/r/CapableOf', '/r/Synonym'})

if __name__ == "__main__":

# Path: ppp_questionparsing_grammatical/nounDB.py
# class TextStream:
# class Nounificator:
#     def __init__(self, directSymbol = ' -> ', inverseSymbol = ' <- ', separator = ', '):
#     def load(self, f):
#     def dump(self, data, f):
#     def __init__(self):
#     def select(self, x):
#     def __str__(self):
#     def __eq__(self, other):
#     def load(self, fileName):
#     def save(self, fileName):
#     def _add(self, verb, noun, target):
#     def addDirect(self, verb, noun):
#     def addInverse(self, verb, noun):
#     def addListDirect(self, verb, nounList):
#     def addListInverse(self, verb, nounList):
#     def _remove(self, verb, noun, target):
#     def removeDirect(self, verb, noun):
#     def removeInverse(self, verb, noun):
#     def _removeVerb(self, verb, target):
#     def removeVerbDirect(self, verb):
#     def removeVerbInverse(self, verb):
#     def _toNouns(self, verb, target):
#     def directNouns(self, verb):
#     def inverseNouns(self, verb):
#     def exists(self, verb):
#     def merge(self, other):


# Path: nounification/nounGenerator.py
import requests
import sys
import os
import time
import pickle
import difflib # string similarity
from conceptnet5.nodes import normalized_concept_name, uri_to_lemmas
from nltk import word_tokenize, pos_tag
from nltk.corpus import wordnet as wn
from ppp_questionparsing_grammatical import nounDB

        cand.processURI()
        cand.posTag()
        return cand
    else:
        return None

def associatedWords(verb, relations):
    """
        Returns the best nb_results candidates to nounify the pattern
    """
    pattern = normalized_concept_name(default_language, verb) # Lemmatization+stemming
    uri = "/c/{0}/{1}".format(default_language, pattern)
    r = requests.get('http://127.0.0.1:8084/data/5.3' + uri, params={'limit':default_lookup_limit}).json()
    res = []
    for e in r['edges']:
        if e['rel'] in relations:
            cand = buildCandidate(pattern, e)
            if cand != None and cand.tag != -1:
                res.append(cand)
    for cand in res:
        cand.computeScore()
    computeWeight(res)
    res.sort(key = lambda x: x.score)
    nb_results = min(len(res), default_number_results)
    return {a.word for a in res[-nb_results:]}

def test(verb):
    return associatedWords(verb, {'/r/RelatedTo', '/r/DerivedFrom', '/r/CapableOf', '/r/Synonym'})

if __name__ == "__main__":

    database = nounDB.Nounificator()