citekey generation and support

This commit is contained in:
Fabien Benureau 2012-10-07 22:11:43 +02:00
parent 3c11994b6f
commit 15782375a5
11 changed files with 88 additions and 18 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
build/
*.pyc
tests/.papers

15
.pit/pit-52bc4daefb7ab51f Normal file
View File

@ -0,0 +1,15 @@
[header]
title = search inside pdfs over a playlist
id = 52bc4daefb7ab51f88974325dd202aaa37f9c60d
status = open
type = feature
author = Fabien Benureau
mail = fabien.benureau+git@gmail.com
date = 2012-10-07 at 20:10 UCT
[eventlog]
opened[0] = opened the 2012-10-07 at 20:10 UCT by Fabien Benureau
[discussion]
desc = # enter your description here

View File

@ -15,7 +15,6 @@ def parser(subparsers, config):
parser.add_argument('bibfile', help='bibtex, bibtexml or bibyaml file')
return parser
def command(config, pdffile, bibfile):
"""
:param pdffilepath path (no url yet) to a pdf or ps file
@ -49,10 +48,13 @@ def command(config, pdffile, bibfile):
print(pretty.bib_desc(bib_data))
files.write_bibdata(bib_data, filename)
papers = files.read_papers()
papers = files.load_papers()
count = papers.get('header', 'count')
papers.set('header', 'count', int(count) + 1)
papers.set('papers', 'p' + count, filename)
citekey = pretty.create_citekey(bib_data)
papers.set('papers', citekey, filename)
papers.set('citekeys', 'ck' + count, citekey)
files.write_papers(papers)
files.write_meta(meta, filename)

View File

@ -30,6 +30,7 @@ def command(config):
papers.add_section('header')
papers.set('header', 'count', 0)
papers.add_section('papers')
papers.add_section('citekeys')
files.write_papers(papers)
else:

View File

@ -1,5 +1,6 @@
from .. import files
from .. import pretty
from .. import color
import subprocess
import tempfile
@ -9,15 +10,16 @@ def parser(subparsers, config):
return parser
def command(config):
papers = files.read_papers()
papers = files.load_papers()
articles = []
for p in papers.options('papers'):
filename = papers.get('papers', p)
number = p[1:]
for p in papers.options('citekeys'):
number = p[2:]
citekey = papers.get('citekeys', p)
filename = papers.get('papers', citekey)
bibdata = files.load_bibdata(filename + '.bibyaml')
bibdesc = pretty.bib_oneliner(bibdata)
articles.append('{:3d} {}'.format(int(number), bibdesc))
articles.append('{:3d} {}{}{}{} {}'.format(int(number), color.purple, citekey, color.end, (8-len(citekey))*' ', bibdesc))
with tempfile.NamedTemporaryFile(suffix=".tmp", delete=True) as tmpf:
tmpf.write('\n'.join(articles))

View File

@ -13,13 +13,17 @@ def parser(subparsers, config):
return parser
def command(config, citekey):
papers = files.read_papers()
papers = files.load_papers()
try:
filename = papers.get('papers', 'p' + str(citekey))
filename = papers.get('papers', str(citekey))
except configparser.NoOptionError:
print('{}error{}: paper with citekey {}{}{} not found{}'.format(
try:
ck = papers.get('citekeys', 'ck'+str(citekey))
filename = papers.get('papers', str(ck))
except configparser.NoOptionError:
print('{}error{}: paper with citekey or number {}{}{} not found{}'.format(
color.red, color.grey, color.cyan, citekey, color.grey, color.end))
exit(-1)
exit(-1)
meta_data = files.load_meta(filename)
filepath = meta_data.get('metadata', 'path')
p = subprocess.Popen(['open', filepath])

View File

@ -106,7 +106,7 @@ def load_externalbibfile(fullbibpath):
def write_papers(config):
write_configfile(config, find_papersdir() + os.sep + 'papers')
def read_papers():
def load_papers():
return read_configfile(find_papersdir() + os.sep + 'papers')
def load_bibdata(filename):

View File

@ -16,8 +16,8 @@ def bib_oneliner(bib_data):
year = article.fields['year']
journal = article.fields['journal']
return '{}{}{} \"{}{}{}\" {}{}{} {}({}{}{}){}'.format(
color.green, authors, color.grey, color.bcyan, title, color.grey,
color.yellow, journal, color.end, color.grey, color.end, year,
color.green, authors, color.grey, color.bcyan, title, color.grey,
color.yellow, journal, color.end, color.grey, color.end, year,
color.grey, color.end)
def bib_desc(bib_data):
@ -25,4 +25,34 @@ def bib_desc(bib_data):
s = '\n'.join('author: {}'.format(person_repr(p)) for p in article.persons['author'])
s += '\n'
s += '\n'.join('{}: {}'.format(k, v) for k, v in article.fields.items())
return s
return s
alphabet = 'abcdefghijklmopqrstuvwxyz'
try:
import ConfigParser as configparser
except ImportError:
import configparser
import files
def create_citekey(bib_data):
"""Create a cite key unique to the paper"""
article = bib_data.entries[list(bib_data.entries.keys())[0]]
first_author = article.persons['author'][0]
year = article.fields['year']
prefix = '{}{}'.format(first_author.last()[0][:6], year[2:])
papers = files.load_papers()
letter = 0, False
citekey = None
citekey = prefix
while not letter[1]:
try:
papers.get('papers', citekey)
citekey = prefix + alphabet[letter[0]]
letter = letter[0]+1, False
except configparser.NoOptionError:
letter = letter[0], True
return citekey

View File

@ -7,7 +7,7 @@
type = {Technical Report},
publisher = {Stanford InfoLab},
year = {1999},
institution = {Stanford InfoLab},
journal = {Stanford InfoLab},
url = {http://ilpubs.stanford.edu:8090/422/},
abstract = {The importance of a Web page is an inherently subjective matter, which depends on the readers interests, knowledge and attitudes. But there is still much that can be said objectively about the relative importance of Web pages. This paper describes PageRank, a mathod for rating Web pages objectively and mechanically, effectively measuring the human interest and attention devoted to them. We compare PageRank to an idealized random Web surfer. We show how to efficiently compute PageRank for large numbers of pages. And, we show how to apply PageRank to search and to user navigation.}
}

View File

@ -0,0 +1,14 @@
@techreport{ilprints422,
number = {1999-66},
month = {November},
author = {Lawrence Page and Sergey Brin and Rajeev Motwani and Terry Winograd},
note = {Previous number = SIDL-WP-1999-0120},
title = {The PageRank Citation Ranking: Bringing Order to the Web.},
type = {Technical Report},
publisher = {Stanford InfoLab},
year = {1999},
institution = {Stanford InfoLab},
url = {http://ilpubs.stanford.edu:8090/422/},
abstract = {The importance of a Web page is an inherently subjective matter, which depends on the readers interests, knowledge and attitudes. But there is still much that can be said objectively about the relative importance of Web pages. This paper describes PageRank, a mathod for rating Web pages objectively and mechanically, effectively measuring the human interest and attention devoted to them. We compare PageRank to an idealized random Web surfer. We show how to efficiently compute PageRank for large numbers of pages. And, we show how to apply PageRank to search and to user navigation.}
}

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
rm -Rf .papers;
papers init;
papers list;
papers add data/pagerank.pdf data/pagerank.bib;
papers list;
papers open 0;
rm -Rf .papers;
papers open Page99;