Ejemplo n.º 1
0
def main():
    testBooks = {
        'Agata_Christie': 'Tajemnica_Wawrzynow.txt',
        'Janusz_A_Zajdel': 'Awaria.txt',
        'Paulo_Coelho': 'Alchemik.txt',
        'George_Orwell': 'Orwell_George_-_Rok_1984.txt',
        'Sapkowski_Andrzej': 'Pani_Jeziora.txt',
        'Andre_Norton': 'Andre_Norton_-_Prekursorka.txt',
        'Dick_Philip_K': 'Dick_Philip_K_-_Kolonia.txt',
        'Gordon_R_Dickson': 'Gordon_R_Dickson_-_Nekromanta.txt',
        'Lem_Stanislaw': 'Lem_Stanislaw_-_Bajki_robotow.txt',
        'Terry_Pratchett': 'Terry_Pratchett_-_Ruchome_Obrazki.txt',
    }
    firstN = 10
    scores = []
    for name, testBook in testBooks.items():
        pFindBest = partial(findBest, tuple(testBooks.values()), testBook)
        result = LocalCache.load(f'{name}.scoreResult', pFindBest)
        score = list(OrderedDict(result).keys()).index(name)
        scores.append(score)

        print(f"Author: {name} has score: {score} for book: {testBook}")
        print(
            f"First {firstN} best results: \n{pprint.pformat(result[:firstN])}\n\n"
        )
    else:
        print(f"scores: {scores}")
        print(
            f"Average score: {sum(scores)/len(testBooks)}, std: {np.std(scores)}"
        )
def getTfIdfModel() -> TfidfModel:
    def _tfIdf():
        loader = getLoaderPrimaryForm()
        tfidf = TfidfModel(loader)
        tfidf.calcVector()
        return tfidf

    return LocalCache.load("tfidf", _tfIdf)
def getGraph(degree) -> GraphModel:
    def _getGraph():
        loader = getLoaderPrimaryForm()
        g = GraphModel(loader, degree)
        g.processGraphs(slice(51555))
        return g

    return LocalCache.load(f'graph{degree}', _getGraph)
def getLoaderPrimaryForm() -> Loader:
    return LocalCache.load('loaderPrimaryForm',
                           lambda: Loader(primaryForm=getPrimaryForm()))
def getPrimaryForm() -> PrimaryForm:
    return LocalCache.load('primaryForm', lambda: PrimaryForm(primaryFormPath))