Notes for the PaperFan project

This notebook will contain preliminary notes for our work on PaperFan

First thing: create a paper class with the metadata

Paper class should have:

  • author(s)
  • title
  • journal
  • year
  • references
  • paper that led you to it
  • overlap percentage (how many of its refs are in your library already)
  • Notes
  • project tag

In [246]:
from rpy2 import *
%load_ext rmagic

In [257]:
import re

In [198]:
#Construct empty dictionary for project tags
projtags = {'AAA': 'Project A', 'BBB': 'Project B'}

#Create function to edit content of notes
def edit_paper_notes(orig_note, retries):
    editnote = raw_input("Do you want to add more notes? (y/n)")
    if editnote in ('y', 'yes', 'Y', 'YES', 'Yes'):
        #if yes, concatenate new notes
        newnote = raw_input("Add notes here:") 
        orig_note = orig_note + " " + newnote
        #print editednote
        return orig_note
    elif editnote in ('n', 'no', 'N', 'NO', 'No'):
        print "OK"
        editednote = orig_note
        return editednote
    else: 
        retries -=1
        if retries <0:
            print "Quitting"
        else:
            print "Please enter y or n"      
            edit_paper_notes(orig_note, retries)
            
            
def addParentPaper(parentpaper, retries):
    addpaper = raw_input("Do you want to add more notes? (y/n)")
    if editnote in ('y', 'yes', 'Y', 'YES', 'Yes'):
        #if yes, concatenate new notes
        newnote = raw_input("Add notes here:") 
        orig_note = orig_note + " " + newnote
        #print editednote
        return orig_note
    elif editnote in ('n', 'no', 'N', 'NO', 'No'):
        print "OK"
        editednote = orig_note
        return editednote
    else: 
        retries -=1
        if retries <0:
            print "Quitting"
        else:
            print "Please enter y or n"      
            edit_paper_notes(orig_note, retries)

In [225]:
#Define the Paper class
class Paper:
    'Class for categorizing all entries of papers'
    #count of all instances of class paper
    total_papers = 0
    #init is the stuff that we'll get from crossref
    def __init__(self, **kwargs):
        self.__dict__.update(kwargs)
        Paper.total_papers +=1
#     def __init__(self, authors, title, journal, year,volume, doi, references):
#         self.authors = authors
#         self.title = title
#         self.journal = journal
#         self.year = year
#         self.volume =volume
#         self.doi = doi
#         self.references = references
         

    #String reprsentation of the class
    def __str__(self):
        return 'This is %d by %d' % (self.title, self.author)
   
    #Give the paper a project tag. It can either be tagged as part of an
    #existing project, or a new project tag can be created
    
    def getProjectTag(self):
        print "Tag", "Project"
        for key, value in projtags.items():
            print key, value
        tag = raw_input("Choose a project tag or enter a new project name (make sure tag is unique):")
        if tag in projtags.keys():
            self.projecttag = projtags[tag]
        else:
            self.projecttag = tag
            newtag = tag[:3].upper();
            projtags[newtag] = tag
            
    #Add notes to the instance of paper
    def editProjectNotes(self):
        #check to see if notes already exist
        if hasattr(self, 'notes'):
            #print "I have notes"
            self.notes = edit_paper_notes(self.notes,4)
            print self.notes
#             #if it exists, print the content and ask if user wants to add more content
#             print self.notes
#             editnote = raw_input("Do you want to add more notes? (y/n)")
#             if editnote == 'y':
#                 #if yes, concatenate new notes
#                newnote = raw_input("Add notes here:") 
#                self.notes = self.notes + "\n" + newnote
#             elif editnote == 'n':
#                 print "OK"
#             else: 
#                 print "Please enter y or n"
#                 editnote = raw_input("Do you want to add more notes? (y/n)")
        else:
            newnote = raw_input("Enter Notes for this paper:")
            self.notes = newnote
            
 #make a dictionary with string names and paper classes
            #look up linked lists
        def addParentpaper(self):
            if hasattr(self,Parentpaper):
                newparent = raw_input("Do you want to enter a new parent paper?")
                
            
        
    
                  
#paper1 = Paper('Ruthie Birger','This is a Paper','Journal of things','2014','My References')

#paper1.getProjectTag()

In [200]:
paper1 = Paper(['Ruthie Birger', 'Emma Fuller'],'This is a Paper','Journal of things','2014','Volume I', 'doiiii','My References')

In [202]:
paper1.editProjectNotes()


Do you want to add more notes? (y/n)sdfsd
Please enter y or n
Do you want to add more notes? (y/n)sdfsd
Please enter y or n
Do you want to add more notes? (y/n)sdgsd
Please enter y or n
Do you want to add more notes? (y/n)sdfsd
Please enter y or n
Do you want to add more notes? (y/n)sds
Quitting
None

In [236]:
BirgerFuller2014 = Paper(authors = ['Ruthie Birger', 'Emma Fuller'],title ='This is a Paper',
                         journal = 'Journal of things', year ='2014',volume ='Volume I', 
                         doi ='doiiii',references ='My References')

In [238]:
BirgerFuller2014.__str__


Out[238]:
<bound method Paper.__str__ of <__main__.Paper instance at 0x104ea3050>>

In [240]:
print projtags.keys()


['AAA', 'BBB']

In [242]:
BirgerFuller2014.getProjectTag()


Tag Project
AAA Project A
BBB Project B
Choose a project tag or enter a new project name (make sure tag is unique):Paperfan Project

In [243]:
BirgerFuller2014.projecttag


Out[243]:
'Paperfan Project'

In [250]:
d1 ="10.1126/science.1239352"
%Rpush d1
%R library(knitcitations)
%R foo = ref(d1)
%Rpull foo

In [260]:
bar = str(foo[0,1])
print bar
print len(bar)
print len(foo[0,0])
world = re.findall(r'"([^"]*)"', bar)
print world


[1] "M. L. Pinsky"    "B. Worm"         "M. J. Fogarty"   "J. L. Sarmiento"
[5] "S. A. Levin"    

98
1
['M. L. Pinsky', 'B. Worm', 'M. J. Fogarty', 'J. L. Sarmiento', 'S. A. Levin']

In [27]:
for item in projtags.items():
    print item[0],":", item[1]


A : Project A
B : Project B

In [29]:
projtags.iteritems


Out[29]:
<function iteritems>

In [30]:
'A' in projtags.keys()


Out[30]:
True

In [151]:
edit_paper_notes(x, 4)


Do you want to add more notes? (y/n)yes
Add notes here:more notes
This is a note
more notes
Out[151]:
'This is a note\nmore notes'

In [268]:
#print foo[0,0]
title_test = re.findall(r'"([^"]*)"', str(foo[0,0]))
authors_test = re.findall(r'"([^"]*)"', str(foo[0,1]))
papertest = Paper(authors = authors_test, title = title_test)

In [269]:
papertest.authors


Out[269]:
['M. L. Pinsky', 'B. Worm', 'M. J. Fogarty', 'J. L. Sarmiento', 'S. A. Levin']

In [ ]:
papertest.