本文整理汇总了Python中note.Note.write方法的典型用法代码示例。如果您正苦于以下问题:Python Note.write方法的具体用法?Python Note.write怎么用?Python Note.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类note.Note
的用法示例。
在下文中一共展示了Note.write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from note import Note [as 别名]
# 或者: from note.Note import write [as 别名]
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 )
示例2: _import
# 需要导入模块: from note import Note [as 别名]
# 或者: from note.Note import write [as 别名]
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()
示例3: _import
# 需要导入模块: from note import Note [as 别名]
# 或者: from note.Note import write [as 别名]
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()
示例4: _write
# 需要导入模块: from note import Note [as 别名]
# 或者: from note.Note import write [as 别名]
def _write(self, uid, data, timestamp=None):
''' Write the document to a file '''
note = Note(uid=uid)
note.write(data)
if timestamp is not None:
note.overwrite_timestamp()
示例5: main
# 需要导入模块: from note import Note [as 别名]
# 或者: from note.Note import write [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-i",
dest = "txt",
help = "The files to be predicted on",
default = os.path.join(BASE_DIR, 'data/test-gold-A.txt')
#default = os.path.join(BASE_DIR, 'data/sms-test-gold-A.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("-o",
dest = "out",
help = "The directory to output predicted files",
default = os.path.join(BASE_DIR, 'data/predictions')
)
# Parse the command line arguments
args = parser.parse_args()
# 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)
# Predict
for txt_file in txt_files:
note = Note()
note.read(txt_file)
X = zip(note.getIDs(),note.getTweets())
labels,confidences = predict_using_model(X, model_path, out_dir)
'''
# Confident predictions
labels_map = {'positive':0, 'negative':1, 'neutral':2}
proxy = []
for t,l,c in zip(note.getTweets(),labels,confidences):
conf = []
for i in range(len(labels_map)):
if i == labels_map[l]: continue
conf.append( c[labels_map[l]] - c[i] )
avg = sum(conf) / len(conf)
start,end,tweet = t
if avg > 1:
#print tweet[start:end+1]
#print l
#print c
#print
#proxy.append(l)
proxy.append('poop')
else:
print 'not conf'
print tweet[start:end+1]
print l
print c
print
proxy.append(l)
#proxy.append('poop')
'''
# output predictions
outfile = os.path.join(out_dir, os.path.basename(txt_file))
note.write( outfile, labels )