コード例 #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)}"
        )
コード例 #2
0
def getTfIdfModel() -> TfidfModel:
    def _tfIdf():
        loader = getLoaderPrimaryForm()
        tfidf = TfidfModel(loader)
        tfidf.calcVector()
        return tfidf

    return LocalCache.load("tfidf", _tfIdf)
コード例 #3
0
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)
コード例 #4
0
def getLoaderPrimaryForm() -> Loader:
    return LocalCache.load('loaderPrimaryForm',
                           lambda: Loader(primaryForm=getPrimaryForm()))
コード例 #5
0
def getPrimaryForm() -> PrimaryForm:
    return LocalCache.load('primaryForm', lambda: PrimaryForm(primaryFormPath))