本文整理匯總了Python中LinkedList.LinkedList.insertSorted方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.insertSorted方法的具體用法?Python LinkedList.insertSorted怎麽用?Python LinkedList.insertSorted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.insertSorted方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Doc
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import insertSorted [as 別名]
class Doc():
def __init__(self, doc):
self.doc = doc;
self.lines = LinkedList();
self.count = 1;
self._iterator = None;
self.documentFrequency = None;
def reset(self):
self.lines.reset();
self._iterator = None;
def __str__(self):
return '\n\t' + str(self.doc) + ', count:' + str(self.count) + self.lines.toString(',');
def __lt__(self, other):
return self.doc < other.doc;
def __eq__(self, other):
return self.doc == other.doc;
def insertLine(self, line):
line = IndexList.Line(int(line));
self.lines.insertSorted(line);
def __iter__(self):
return self;
def next(self):
if self._iterator is None:
if self.lines._head is None: raise StopIteration
self._iterator = self.lines._head;
return self._iterator.value;
self._iterator = self._iterator.next;
if self._iterator is None: raise StopIteration
return self._iterator.value;
示例2: search
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import insertSorted [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;
示例3: Term
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import insertSorted [as 別名]
class Term():
def __init__(self, term):
self.term = term;
self.docs = LinkedList();
self.count = 1;
self._iterator = None;
self._temp = None;
def __str__(self):
return "Term: " + self.term + ', count:' + str(self.count) + self.docs.toString(',');
def __lt__(self, other):
return self.term < other.term;
def __eq__(self, other):
return self.term == other.term;
def reset(self):
self.docs.reset();
self._iterator = None;
def insertDoc(self, doc, line):
obj = IndexList.Doc(doc);
current = self.docs.getLastItemOf(obj);
if current:
current.count += 1;
else:
self.docs.insertSorted(obj);
current = obj;
current.insertLine(line);
def __iter__(self):
return self;
def next(self):
if self._temp is None:
if self.terms is None: raise StopIteration
self._temp = self.terms;
if self._temp._currentNode is None: raise StopIteration
value = self._temp._currentNode.value;
self._temp._currentNode = self._temp._currentNode.next;
return value;
def __iter__(self):
return self;
def next(self):
if self._iterator is None:
if self.docs._head is None: raise StopIteration
self._iterator = self.docs._head;
return self._iterator.value;
self._iterator = self._iterator.next;
if self._iterator is None: raise StopIteration
return self._iterator.value;
示例4: tfidf
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import insertSorted [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
示例5: IndexList
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import insertSorted [as 別名]
class IndexList():
def __init__(self):
self.objs = LinkedList();
self._iterator = None;
def __str__(self):
return self.objs.toString('\n');
def reset(self):
self.objs.reset();
self._iterator = None;
def insert(self, string1, string2, string3):
obj = IndexList.Term(string1);
current = self.objs.getLastItemOf(obj);
if current:
current.count += 1;
else:
self.objs.insertSorted(obj);
current = obj;
current.insertDoc(string2, string3);
return current;
def __iter__(self):
return self;
def next(self):
if self._iterator is None:
if self.objs._head is None: raise StopIteration
self._iterator = self.objs._head;
return self._iterator.value;
self._iterator = self._iterator.next;
if self._iterator is None: raise StopIteration
return self._iterator.value;
class Term():
def __init__(self, term):
self.term = term;
self.docs = LinkedList();
self.count = 1;
self._iterator = None;
self._temp = None;
def __str__(self):
return "Term: " + self.term + ', count:' + str(self.count) + self.docs.toString(',');
def __lt__(self, other):
return self.term < other.term;
def __eq__(self, other):
return self.term == other.term;
def reset(self):
self.docs.reset();
self._iterator = None;
def insertDoc(self, doc, line):
obj = IndexList.Doc(doc);
current = self.docs.getLastItemOf(obj);
if current:
current.count += 1;
else:
self.docs.insertSorted(obj);
current = obj;
current.insertLine(line);
def __iter__(self):
return self;
def next(self):
if self._temp is None:
if self.terms is None: raise StopIteration
self._temp = self.terms;
if self._temp._currentNode is None: raise StopIteration
value = self._temp._currentNode.value;
self._temp._currentNode = self._temp._currentNode.next;
return value;
def __iter__(self):
return self;
def next(self):
if self._iterator is None:
if self.docs._head is None: raise StopIteration
self._iterator = self.docs._head;
return self._iterator.value;
self._iterator = self._iterator.next;
if self._iterator is None: raise StopIteration
return self._iterator.value;
class Doc():
def __init__(self, doc):
self.doc = doc;
self.lines = LinkedList();
self.count = 1;
self._iterator = None;
self.documentFrequency = None;
def reset(self):
self.lines.reset();
self._iterator = None;
def __str__(self):
return '\n\t' + str(self.doc) + ', count:' + str(self.count) + self.lines.toString(',');
def __lt__(self, other):
return self.doc < other.doc;
def __eq__(self, other):
return self.doc == other.doc;
def insertLine(self, line):
line = IndexList.Line(int(line));
self.lines.insertSorted(line);
#.........這裏部分代碼省略.........