Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/exportannotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def _exportAnnoFile(abpath_out,anno,verbose=True):
- @citationkey
- Tags: @tag1, @tag2, @tag3...
- Ctime: creation time
- Page: page number (ordinal)
- Colour: highlight colour

-----------------------------------------------------
# Title of another PDF
Expand All @@ -56,6 +58,8 @@ def _exportAnnoFile(abpath_out,anno,verbose=True):
- @citationkey
- Tags: @tag1, @tag2, @tag3...
- Ctime: creation time
- Page: page number (ordinal)
- Colour: highlight colour

Use tabs in indention, and markup syntax: ">" for highlights, and "-" for notes.

Expand Down Expand Up @@ -105,8 +109,10 @@ def _exportAnnoFile(abpath_out,anno,verbose=True):
\t\t- @{1}
\t\t- Tags: {2}
\t\t- Ctime: {3}
\t\t- Page: {4}
\t\t- Color: {5}
'''.format(*map(conv,[hlstr, hljj.citationkey,\
tagstr, hljj.ctime]))
tagstr, hljj.ctime, hljj.page, hljj.color]))

#outstr=outstr.encode('ascii','replace')
outstr=outstr.encode('utf8','replace')
Expand All @@ -126,8 +132,10 @@ def _exportAnnoFile(abpath_out,anno,verbose=True):
\t\t- @{1}
\t\t- Tags: {2}
\t\t- Ctime: {3}
\t\t- Page: {4}
\t\t- Color: {5}
'''.format(*map(conv,[ntstr, ntjj.citationkey,\
tagstr, ntjj.ctime]))
tagstr, ntjj.ctime, ntjj.page, ntjj.color]))

#outstr=outstr.encode('ascii','replace')
outstr=outstr.encode('utf8','replace')
Expand Down
6 changes: 4 additions & 2 deletions lib/extracthl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@

#------Store highlighted texts with metadata------
class Anno(object):
def __init__(self,text,ctime=None,title=None,author=None,\
def __init__(self,text,ctime=None,color=None,title=None,author=None,\
note_author=None,page=None,citationkey=None,tags=None):

self.text=text
self.ctime=ctime
self.color=color
self.title=title
self.author=author
self.note_author=note_author
Expand All @@ -56,8 +57,9 @@ def __repr__(self):
Creation time: %s
Paper title: %s
Annotation author: %s
Page: %s
Citation key: %s
Annotation color: %s
Page: %s
Tags: %s
''' %(self.text, self.ctime, self.title,\
self.note_author, self.page, self.citationkey,\
Expand Down
17 changes: 15 additions & 2 deletions lib/extracthl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from numpy import sqrt, argsort

from subprocess import Popen, PIPE
from collections import Counter
import tools
import time
import wordfix
Expand All @@ -58,11 +59,12 @@ def checkPdftotext():

#------Store highlighted texts with metadata------
class Anno(object):
def __init__(self,text,ctime=None,title=None,author=None,\
def __init__(self,text,ctime=None,color=None,title=None,author=None,\
note_author=None,page=None,citationkey=None,tags=None):

self.text=text
self.ctime=ctime
self.color=color
self.title=title
self.author=author
self.note_author=note_author
Expand All @@ -83,10 +85,11 @@ def __repr__(self):
Paper title: %s
Annotation author: %s
Page: %s
Annotation color: %s
Citation key: %s
Tags: %s
''' %(self.text, self.ctime, self.title,\
self.note_author, self.page, self.citationkey,\
self.note_author, self.page, self.color, self.citationkey,\
', '.join(self.tags))

reprstr=reprstr.encode('ascii','replace')
Expand Down Expand Up @@ -591,6 +594,14 @@ def getCtime(annos,verbose=True):
return ctimes[-1]


#----------------Get the color of annos----------------
def getColor(annos):
'''Get the most common color for a list of annos
'''

colors = Counter([ii['color'] for ii in annos])
most_common_color_code = colors.most_common(1)[0][0]
return tools.color_labels.get(most_common_color_code, most_common_color_code)



Expand Down Expand Up @@ -645,6 +656,7 @@ def extractHighlights(filename,anno,verbose=True):
#--------------Attach text with meta--------------
textjj=Anno(textjj,\
ctime=getCtime(anno.highlights[ii+1]),\
color=getColor(anno.highlights[ii+1]),\
title=anno.meta['title'],\
page=ii+1,citationkey=anno.meta['citationkey'],\
tags=anno.meta['tags'])
Expand Down Expand Up @@ -719,6 +731,7 @@ def extractHighlights2(filename,anno,verbose=True):
#--------------Attach text with meta--------------
textjj=Anno(textjj,\
ctime=getCtime(annoii),\
color=getColor(annoii),\
title=anno.meta['title'],\
page=ii+1,citationkey=anno.meta['citationkey'],\
tags=anno.meta['tags'])
Expand Down
3 changes: 3 additions & 0 deletions lib/extractnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Update time: 2016-04-12 22:09:38.
'''

import tools

#-----------------Extract notes-----------------
def extractNotes(path,anno,verbose=True):
Expand All @@ -35,7 +36,9 @@ def extractNotes(path,anno,verbose=True):
for pp in anno.ntpages:

for noteii in notes[pp]:
note_color=tools.color_labels.get(noteii['color'], noteii['color'])
textjj=Anno(noteii['content'], ctime=noteii['cdate'],\
color=note_color,\
title=meta['title'],\
page=pp,citationkey=meta['citationkey'], note_author=noteii['author'],\
tags=meta['tags'])
Expand Down
2 changes: 1 addition & 1 deletion lib/extracttags.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def exportAnno(annodict,outdir,action,verbose=True):
os.remove(abpath_out)

if verbose:
printHeader('Exporting all taged annotations to:',3)
printHeader('Exporting all tagged annotations to:',3)
printInd(abpath_out,4)

conv=lambda x:unicode(x)
Expand Down
11 changes: 10 additions & 1 deletion lib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
import os
import re


color_labels = {
'#fff5ad': 'Yellow',
'#dcffb0': 'Green',
'#bae2ff': 'Blue',
'#d3c2ff': 'Purple',
'#ffc4fb': 'Pink',
'#ffb5b6': 'Red',
'#ffdeb4': 'Orange',
'#dbdbdb': 'Grey'
}

def deu(text):
if isinstance(text,str):
Expand Down
16 changes: 11 additions & 5 deletions menotexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,14 @@ def getHighlights(db,results=None,folderid=None,foldername=None,filterdocid=None
}
where hl1={'rect': bbox,
'cdate': cdate,
'page':pg}
'page':pg,
'color': color}
note={'rect': bbox,
'author':author,
'content':txt,
'cdate': cdate,
'page':pg}
'page':pg,
'color': color}

Update time: 2016-02-24 00:36:33.
'''
Expand Down Expand Up @@ -426,6 +428,7 @@ def getNotes(db,results=None,folderid=None,foldername=None,filterdocid=None):
FileNotes.author, FileNotes.note,
FileNotes.modifiedTime,
FileNotes.documentId,
FileNotes.color,
DocumentFolders.folderid,
Folders.name
FROM Files
Expand All @@ -443,7 +446,8 @@ def getNotes(db,results=None,folderid=None,foldername=None,filterdocid=None):
FileNotes.x, FileNotes.y,
FileNotes.author, FileNotes.note,
FileNotes.modifiedTime,
FileNotes.documentId
FileNotes.documentId,
FileNotes.color
FROM Files
LEFT JOIN FileNotes
ON FileNotes.fileHash=Files.hash
Expand Down Expand Up @@ -474,16 +478,18 @@ def getNotes(db,results=None,folderid=None,foldername=None,filterdocid=None):
txt = r[5]
cdate = convert2datetime(r[6])
docid=r[7]
color=r[8]
if filterdocid is None:
folder=r[9]
folder=r[10]
else:
folder=None

note = {'rect': bbox,\
'author':author,\
'content':txt,\
'cdate': cdate,\
'page':pg\
'page':pg,\
'color':color\
}

#------------Save to dict------------
Expand Down