def search(self): s = Search(unicode(self.form.searchLine.text())) for i, doi in enumerate(s): if i == 5: break doc = get_document(doi) authors = ', '.join([a.name for a in doc.authors.all()]) self.addResult(unicode(doc.title), unicode(authors), unicode(doc.year), doc) self.parent.app.processEvents()
def findCitedIn(self): row = self.form.searchResults.currentRow() doc = self.form.searchResults.item(row, 0).data(Qt.UserRole).toPyObject() self.clear() for doi in doc.citings.split(';'): cited_doc = get_document(doi) authors = ', '.join([a.name for a in cited_doc.authors.all()]) self.addResult(unicode(cited_doc.title), unicode(authors), unicode(cited_doc.year), cited_doc) self.parent.app.processEvents()
def addParentsToWidget(self, widget, prepend=None): doc = get_document(self.doi) item = QTreeWidgetItem(prepend, QStringList([unicode(doc.title)])) if prepend == None: # add to root widget.insertTopLevelItem( 0, item ) else: # add to prepend item prepend.addChild( item ) for c in self.parents: c.addParentsToWidget(widget, item)
def addChildrenToWidget(self, widget, prepend=None): # prepend is the item that we append to, it is None for the root doc = get_document(self.doi) item = QTreeWidgetItem(prepend, QStringList([unicode(doc.title)])) if prepend == None: # add to root widget.insertTopLevelItem( 0, item ) else: # add to prepend item prepend.addChild( item ) for c in self.children: c.addChildrenToWidget(widget, item)
def rebuildDAG(self): # we will only build a DAG with the nodes that actually have a relationship # all single nodes are omitted, this includes the ones without a known DOI allDois = [] DAG = [] papers = KKDocument.objects.all() for p in papers: if p.doi != "": allDois.append( p.doi ) allDois = uniq( allDois ) for doi in allDois: doc = get_document(doi) for c in doc.citings.split(';'): if c in allDois: child = self.cleanAndWrapStr(get_document(c).title) parent = self.cleanAndWrapStr(get_document(doi).title) DAG.append( (parent, child) ) import pydot g = pydot.graph_from_edges(DAG, directed=True) g.write_jpeg('dag.jpg', prog='dot')
def rebuildTree(self): # just add all entries that don't have a doi # build a tree with the rest doiTreeNodes = {} allDois = [] papers = KKDocument.objects.all() for p in papers: if p.doi == "": tree(p.doi).addChildrenToWidget( self.infoTree ) else: allDois.append( p.doi ) allDois = uniq( allDois ) for doi in allDois: doiTreeNodes[doi] = tree(doi) for doi in allDois: doc = get_document(doi) for c in doc.citings.split(';'): if c in allDois: doiTreeNodes[doi].newChild( doiTreeNodes[c] ) doiTreeNodes[c].addParent( doiTreeNodes[doi] ) self.infoTree.clear() reverse = False if reverse: for doi in allDois: if doiTreeNodes[doi].isLeaf(): doiTreeNodes[doi].addParentsToWidget( self.infoTree ) else: for doi in allDois: if doiTreeNodes[doi].isRoot(): doiTreeNodes[doi].addChildrenToWidget( self.infoTree )
def lookUpDOI(self): doi = unicode(self.form.searchLine.text()) doc = get_document(doi) authors = ', '.join([a.name for a in doc.authors.all()]) self.addResult(unicode(doc.title), unicode(authors), unicode(doc.year), doc) self.parent.app.processEvents()