コード例 #1
0
    try:
        int(x)
        return x
    except ValueError:
        if(x in number_dic.keys()):
            return number_dic[x]
        else:
            return "";

def make_nice(text):
    text = [replace_int(x) for x in text.split('_') if replace_int(x) != ""]
    return(" ".join(text))

ppdensity_grammar = "PPDENSITY: {<CD>+<PPUNIT><PER><AREA>+}"

hasPopulationDensity = relation('hasPopulationDensity' , 'GPE' , 'PPDENSITY' , make_nice , patterns_list=[
    {'left': UNIVERSAL, 'middle': HAS_POPULATION_DENSITY_MORE, 'comparator': 'more', 'inverted':True},
    {'left': UNIVERSAL, 'middle': HAS_POPULATION_DENSITY_LESS, 'comparator': 'less', 'inverted':True},
    {'left': UNIVERSAL, 'middle': HAS_POPULATION_DENSITY, 'comparator': 'egal', 'inverted':True},
    {'left': S_POPULATION_DENSITY, 'middle': IS_MORE, 'comparator': 'more', 'inverted':True},
    {'left': POPULATION_DENSITY_OF, 'middle': IS_MORE, 'comparator': 'more', 'inverted':True},
    {'left': S_POPULATION_DENSITY, 'middle': IS_LESS, 'comparator': 'less', 'inverted':True},
    {'left': POPULATION_DENSITY_OF, 'middle': IS_LESS, 'comparator': 'less', 'inverted':True},
    {'left': S_POPULATION_DENSITY, 'middle': IS, 'comparator': 'egal', 'inverted':True},
    {'left': POPULATION_DENSITY_OF, 'middle': IS, 'comparator': 'egal', 'inverted':True},
])

listeRelation.append(hasPopulationDensity)
grammar.append(ppdensity_grammar)
dic.update(ppdensity_dic)
コード例 #2
0
        int(x)
        return x
    except ValueError:
        if x in number_dic.keys():
            return number_dic[x]
        else:
            return ""


def make_nice(text):
    text = [replace_int(x) for x in text.split("_")]
    return "".join(text)


hasPopulation = relation(
    "hasPopulation",
    "PPCD",
    "GPE",
    make_nice,
    patterns_list=[
        {"left": UNIVERSAL, "middle": LIVE_IN, "comparator": "egal"},
        {"left": THERE, "middle": IN, "comparator": "egal"},
        {"left": THERE_MORE, "middle": IN, "comparator": "more"},
        {"left": THERE_LESS, "middle": IN, "comparator": "less"},
    ],
)

listeRelation.append(hasPopulation)
dic.update(haspop_dic)
grammar.append(haspop_grammar)