本文整理汇总了Python中note.Note类的典型用法代码示例。如果您正苦于以下问题:Python Note类的具体用法?Python Note怎么用?Python Note使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Note类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getpubs
def getpubs():
"""Get Publisher initials and names from '__Publish Name and Initials'"""
import html2text # pip install html2text
import re
from note import Note
from models import ENNote
id = 90 # in table
title = '__Publish Name and Initials'
pubinitialsguid = '97a296aa-9698-4e29-bf74-3baa8e131ca1'
territorypoisguid = '658ad719-3492-4882-b0f7-f52f67a7f7fa'
#note_pubinitials = ENNote.objects.get(guid=pubinitialsguid)
note_pubinitials = ENNote.objects.get(id=90)
NotePubInitials = Note(note_pubinitials.content)
txt = NotePubInitials.parseNoteContentToMarkDown()
reobj = re.compile(r"(?P<lastname>.+?)\s*,\s*(?P<firstname>.+?)\s*-\s*_(?P<initials>[A-Z]+)")
match = reobj.search(txt)
if not match:
raise Exception("Failed to match publisher initials in: %s" % txt)
publishers = {}
for match in reobj.finditer(txt):
publishers[match.group("initials")] = "%s, %s" % (match.group("lastname"), match.group("firstname"))
return publishers
示例2: main
def main():
"""
main()
Purpose: This program builds an SVM model for Twitter classification
"""
parser = argparse.ArgumentParser()
parser.add_argument("-t",
dest = "txt",
help = "The files that contain the training examples",
default = os.path.join(BASE_DIR, 'data/twitter-train-cleansed-B.tsv')
)
parser.add_argument("-m",
dest = "model",
help = "The file to store the pickled model",
default = os.path.join(BASE_DIR, 'models/awesome')
)
parser.add_argument("-g",
dest = "grid",
help = "Perform Grid Search",
action='store_true',
default = False
)
# Parse the command line arguments
args = parser.parse_args()
grid = args.grid
# Decode arguments
txt_files = glob.glob(args.txt)
model_path = args.model
if not txt_files:
print 'no training files :('
sys.exit(1)
# Read the data into a Note object
notes = []
for txt in txt_files:
note_tmp = Note()
note_tmp.read(txt)
notes.append(note_tmp)
# Get data from notes
X = []
Y = []
for n in notes:
X += zip(n.sid_list(), n.text_list())
Y += n.label_list()
# Build model
train(X, Y, model_path, grid)
示例3: reset
def reset(cls):
"""Reset to default state."""
Box.reset()
Note.reset()
Figure.reset()
Table.reset()
Video.reset()
示例4: Melody
class Melody(object):
notes = [ ]
def __init__(self):
self.NOTE = Note()
def transpose(self, k):
value = [ ]
for note in self.notes:
i = self.NOTE.index(note)
j = i + k
note2 = self.NOTE.note(j)
value.append(note2)
return value
def reverse(self):
value = [ ]
for note in self.notes:
value = [note] + value
return value
def invert(self):
base = self.NOTE.index(self.notes[0])
value = [ ]
for note in self.notes:
k = self.NOTE.index(note)
kk = 2*base - k
note2 = self.NOTE.note(kk)
value.append(note2)
return value
示例5: parse_metadata
def parse_metadata(root):
notes = {}
for page in root.find('pageList').findall('page'):
pg = int(page.attrib['number'])
annotlist = page.find('annotationList')
for annot in annotlist.findall('annotation'):
if ( annot.attrib['type'] == "1" and
pg <= self.ui.documentWidget.num_pages ):
base = annot.find('base')
try:
author = base.attrib['author']
except KeyError:
author = ''
try:
text = base.attrib['contents']
except KeyError:
text = ''
try:
cdate = base.attrib['creationDate']
except KeyError:
cdate = ''
try:
mdate = base.attrib['modifyDate']
except KeyError:
mdate = ''
try:
preamble = base.attrib['preamble']
except KeyError:
preamble = PREAMBLE
try:
uname = base.attrib['uniqueName']
# notorius-1-0 becomes 0
uid = int(uname.rsplit('-')[-1])
except KeyError:
try:
uid = max(notes.keys())
except ValueError:
uid = 0
boundary = base.find('boundary')
x = float(boundary.attrib['l'])
y = float(boundary.attrib['t'])
size = self.ui.documentWidget.Document.page(
pg).pageSizeF()
pos = QtCore.QPointF(x*size.width(),
y*size.height())
note = Note(text, preamble, page = pg, pos = pos,
uid = uid)
notes[uid] = note
note.cdate = datetime.datetime.strptime(cdate, "%Y-%m-%dT%H:%M:%S")
note.mdate = datetime.datetime.strptime(mdate, "%Y-%m-%dT%H:%M:%S")
note.update()
else:
self.okular_notes.append(annot)
return notes
示例6: main
def main():
"""
main()
Purpose: This program builds an SVM model for Twitter classification
"""
parser = argparse.ArgumentParser()
parser.add_argument("-t",
dest = "txt",
help = "Files that contain the training examples (e.g. data/demo.tsv)",
)
parser.add_argument("-m",
dest = "model",
help = "The file to store the pickled model (e.g. models/demo.model)",
)
# Parse the command line arguments
args = parser.parse_args()
if (not args.txt) or (not args.model):
parser.print_help()
exit(1)
# Decode arguments
txt_files = glob.glob(args.txt)
model_path = args.model
if not txt_files:
print 'no training files :('
sys.exit(1)
# Read the data into a Note object
notes = []
for txt in txt_files:
note_tmp = Note()
note_tmp.read(txt)
notes.append(note_tmp)
# Get data from notes
X = []
Y = []
for n in notes:
X += zip(n.sid_list(), n.text_list())
Y += n.label_list()
# Build model
train(X, Y, model_path)
示例7: kick_drum_line
def kick_drum_line(composition, drop_number):
new_note_list = []
duration = 44100 / 8
drop_increment = duration / drop_number
for i, note in enumerate(composition.get_notes()):
effect_start_time = note.get_start_time() - duration
effect_end_time = note.get_start_time()
if effect_start_time < 0 :
new_note_list.append(note)
continue
if i != 0:
if note.is_kick():
rollback = 0
indices_in_notes_list = len(new_note_list) - 1
#keep rolling back until "in drop time" notes are popped off
while True:
last_note = new_note_list[-1]
if last_note.get_start_time() > (last_note.get_end_time() - duration):
new_note_list.pop()
else:
break
last_note = new_note_list[-1]
last_note.set_end_time(effect_start_time)
scale = composition.get_scale()
closest = utilities.find_closest(scale, note.get_frequency())
index = scale.index(closest) + drop_number
ampl = note.get_amplitude()
for x in range(0, drop_number):
new_s_time = int(effect_start_time + x * drop_increment)
new_e_time = int(effect_start_time + (x+1) * drop_increment)
new_freq = scale[index]
nn = Note(new_s_time, new_e_time, new_freq, ampl)
nn.set_kick(True)
new_note_list.append(nn)
index -=1
new_note_list.append(note)
else:
new_note_list.append(note)
composition.notes = new_note_list
示例8: edit_notes
def edit_notes(mn, config_store, args):
"""
Display search results and allow edits.
:param Mininote mn: Mininote instance
:param ConfigStore config_store: User configuration
:param argparse.Namespace args: Command line options
"""
from match_notes import match_notes
text_editor = args.text_editor
before_notes = list(mn.search(args.note))
before_formatted_notes = '\r\n'.join(map(str, before_notes))
after_formatted_notes = text_editor.edit(before_formatted_notes)
try:
nonblank_lines = filter(lambda line: len(line.strip()) > 0, after_formatted_notes.splitlines())
after_notes = map(Note.parse_from_str, nonblank_lines)
except NoteParseError:
logger.error("Unable to parse changes to notes. Session is saved in {}".format(text_editor.path))
return
text_editor.cleanup()
before_notes_reparsed = map(lambda n: Note.parse_from_str(str(n)), before_notes)
pairs = match_notes(before_notes_reparsed, after_notes)
for before, after in pairs:
if before is None:
mn.add_note(after_notes[after])
elif after is None:
mn.delete_note(before_notes[before])
elif before_notes[before].text != after_notes[after].text:
before_notes[before].text = after_notes[after].text
mn.update_note(before_notes[before])
示例9: save
def save(self):
buff = self.get_buffer()
text = buff.get_text(buff.get_start_iter(), buff.get_end_iter())
if not self.note:
import utils
self.note = Note(utils.generate_filename(), utils.user_configurations['TIXPATH'], text)
self.note.write_text_to_file(text)
return self.note
示例10: main
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-i",
dest = "txt",
help = "The files to be predicted on (e.g. data/demo.tsv)",
)
parser.add_argument("-m",
dest = "model",
help = "The file to store the pickled model (e.g. models/demo.model)",
)
parser.add_argument("-o",
dest = "out",
help = "The directory to output predicted files (e.g. data/predictions)",
)
# Parse the command line arguments
args = parser.parse_args()
if (not args.txt) or (not args.model) or (not args.out):
parser.print_help()
exit(1)
# Decode arguments
txt_files = glob.glob(args.txt)
model_path = args.model
out_dir = args.out
# Available data
if not txt_files:
print 'no predicting files :('
exit(1)
# Load model
with open(model_path+'.model', 'rb') as fid:
clf = pickle.load(fid)
with open(model_path+'.dict', 'rb') as fid:
vec = pickle.load(fid)
# Predict labels for each file
for pfile in txt_files:
note = Note()
note.read(pfile)
XNotNormalized = zip(note.sid_list(), note.text_list())
X = XNotNormalized
#X = normalize_data_matrix(XNotNormalized)
# Predict
labels = predict( X, clf, vec )
# output predictions
outfile = os.path.join(out_dir, os.path.basename(pfile))
note.write( outfile, labels )
示例11: get_all_notes
def get_all_notes():
G_ = Note('G#', 'Ab', None)
G = Note('G', '', G_)
F_ = Note('F#', 'Gb', G)
F = Note('F', '', F_)
E = Note('E', '', F)
D_ = Note('D#', 'Eb', E)
D = Note('D', '', D_)
C_ = Note('C#', 'Db', D)
C = Note('C', 'C', C_)
B = Note('B', '', C)
A_ = Note('A#', 'Bb', B)
A = Note('A', '', A_)
G_.NextNote = A
A.PrevNote = G_
return [A, A_, B, C, C_, D, D_, E, F, F_, G, G_]
示例12: _import
def _import(self):
self.noteList = {}
for infile in glob.glob(os.path.join(os.path.expanduser("~/.conboy"), "*.note")):
try:
parser = xml.sax.make_parser()
handler = textHandler()
parser.setContentHandler(handler)
parser.parse(infile)
except Exception:
import traceback
print traceback.format_exc()
try:
note = Note()
uuid = handler._content.split("\n", 1)[0].strip(" \t\r\n")
uuid = getValidFilename(uuid)
path = os.path.join(note.NOTESPATH, uuid)
if os.path.exists(path + ".txt"):
index = 2
while os.path.exists(os.path.join(note.NOTESPATH, "%s %s.txt" % (path, unicode(index)))):
index = index + 1
uuid = "%s %s" % (os.path.basename(path), unicode(index))
note.uuid = uuid + ".txt"
note.write(handler._content)
try:
from rfc3339.rfc3339 import strtotimestamp
mtime = strtotimestamp(handler._last_change)
lpath = os.path.join(Note.NOTESPATH, note.uuid)
os.utime(lpath, (-1, mtime))
except Exception:
import traceback
print traceback.format_exc()
except Exception:
import traceback
print traceback.format_exc()
self._set_running(False)
self.on_finished.emit()
示例13: _import
def _import(self):
self.noteList = {}
for infile in glob.glob( \
os.path.join(os.path.expanduser('~/.conboy'), '*.note')):
try:
parser = xml.sax.make_parser()
handler = textHandler()
parser.setContentHandler(handler)
parser.parse(infile)
except Exception, err:
import traceback
print traceback.format_exc()
try:
note = Note()
uuid = handler._content.split('\n', 1)[0].strip(' \t\r\n')
uuid = getValidFilename(uuid)
path = os.path.join(note.NOTESPATH, uuid)
if os.path.exists(path + '.txt'):
index = 2
while (os.path.exists(os.path.join( \
note.NOTESPATH,'%s %s.txt' \
% (path, \
unicode(index))))):
index = index + 1
uuid = ('%s %s' \
% (os.path.basename(path), \
unicode(index)))
note.uuid = uuid + '.txt'
note.write(handler._content)
try:
from rfc3339.rfc3339 import strtotimestamp
mtime = strtotimestamp(handler._last_change)
lpath = os.path.join(Note.NOTESPATH, note.uuid)
os.utime(lpath, (-1, mtime))
except Exception, err:
import traceback
print traceback.format_exc()
except Exception, err:
import traceback
print traceback.format_exc()
示例14: show_notes
def show_notes(noteId=None):
if noteId:
notes = (list(db.notes.find({'noteId': noteId})))
print notes
if notes:
note = Note.from_json(notes[0]) # convert to python object
note_title = note.title
content = note.content
noteId = note.noteId
return render_template('show_note.html', title=note_title, content=content, noteId=noteId)
示例15: __init__
def __init__(self):
logging.debug('Initializing Data class')
self.DueDate = DueDate()
self.Reminder = Reminder()
self.Note = Note()
self.ID = 'Database'
self.dbDict = {
'Database':{
'DueDate':{
DueDate.returndDict()
},
'Reminder':{
Reminder.returnrDict()
},
'Note':{
Note.returnnDict()
}
}
}