當前位置: 首頁>>代碼示例>>Python>>正文


Python LinkedList.printSep方法代碼示例

本文整理匯總了Python中LinkedList.LinkedList.printSep方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.printSep方法的具體用法?Python LinkedList.printSep怎麽用?Python LinkedList.printSep使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在LinkedList.LinkedList的用法示例。


在下文中一共展示了LinkedList.printSep方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: search

# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import printSep [as 別名]
    def search(self, query, queryExpansionParameter):
        orderedQueryResults                      = self.tfidf(query);
        if orderedQueryResults is None: return None;
        mostRelevantDocumentId                   = orderedQueryResults.getHead().docId;
        mostRelevantDocumentIdDocumentCollection = int(self._documentIds[mostRelevantDocumentId]);
        orderedExpansionTerms                    = LinkedList();
        orderedExpansionTerms.printSep           = "\n";

        uniqueTerms  = {};
        currentDoc   = self._docCollect.nextDocument();
        currentDocId = int(currentDoc.getName());
        while currentDocId != mostRelevantDocumentIdDocumentCollection:
            currentDoc   = self._docCollect.nextDocument();
            currentDocId = int(currentDoc.getName());

        # current doc now has the document that is the highest ranked tfid result
        self._tokenizer.loadDocument(currentDoc);

        # generate unique query term set
        token, position = self._tokenizer.nextToken()
        while token is not None:
            uniqueTerms[token] = position;
            token, position = self._tokenizer.nextToken();

        # calculate tfidf scores for each token and insert into ordered linked list
        for token, pos in uniqueTerms.iteritems():
            tfidf = self.tfidf_term(token, mostRelevantDocumentIdDocumentCollection);
            orderedExpansionTerms.insertSorted(QueryResultItem(token, tfidf));

        # expand query with most relevant query terms:
        currentNode = orderedExpansionTerms._head;
        for i in xrange(0,queryExpansionParameter):
            currentData = currentNode.value.docId;
            query += " " + currentData;
            currentNode = currentNode.next;

        # perform search with appended query

        results = self.tfidf(query);
        current = results._head;
        rank    = 0;

        print("\n\nComplete query:");
        print(query)
        print("results:\n")

        while current is not None:
            print str(self._currentQueryId) + " 0 " + str(current.value.docId) + " " + str(rank) + " " + str(current.value.tfidf) + " 0";
            current = current.next;
            rank += 1;

        self._currentQueryId += 1;
開發者ID:anconaesselmann,項目名稱:pySearch,代碼行數:54,代碼來源:SearchEngine.py

示例2: tfidf

# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import printSep [as 別名]
 def tfidf(self, query):
     queryTokens  = self._queryTokenizer.tokenize(query);
     postingLists = self._getPostingLists(queryTokens);
     documentScores = {};
     # create document scores
     for term in postingLists:
         if term is None: return;
         for doc in term:
             termFrequency = 1 + math.log10(float(doc.count) / float(self.termFrequencies[int(doc.doc) - 1]))
             docSocre = termFrequency * self._getIDF(term);
             if str(doc.doc) in documentScores.keys(): documentScores[str(doc.doc)] += docSocre;
             else: documentScores[str(doc.doc)] = docSocre;
     # create an ordered list of documents, ordered by document score
     orderedQueryResults = LinkedList();
     orderedQueryResults.printSep = "\n";
     for docId, ds in documentScores.iteritems():
         orderedQueryResults.insertSorted(QueryResultItem(docId, ds));
     return orderedQueryResults
開發者ID:anconaesselmann,項目名稱:pySearch,代碼行數:20,代碼來源:SearchEngine.py


注:本文中的LinkedList.LinkedList.printSep方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。