本文整理汇总了Python中message.Messager类的典型用法代码示例。如果您正苦于以下问题:Python Messager类的具体用法?Python Messager怎么用?Python Messager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Messager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_match_regex
def _get_match_regex(text, text_match="word", match_case=False,
whole_string=False):
"""
Helper for the various search_anns_for_ functions.
"""
if match_case:
regex_flags = 0
else:
regex_flags = re.IGNORECASE
if text is None:
text = ''
if text_match == "word":
# full word match: require word boundaries or, optionally,
# whole string boundaries
if whole_string:
return re.compile(r'^'+re.escape(text)+r'$', regex_flags)
else:
return re.compile(r'\b'+re.escape(text)+r'\b', regex_flags)
elif text_match == "substring":
# any substring match, as text (nonoverlapping matches)
return re.compile(re.escape(text), regex_flags)
elif text_match == "regex":
try:
return re.compile(text, regex_flags)
except: # whatever (sre_constants.error, other?)
Messager.warning('Given string "%s" is not a valid regular expression.' % text)
return None
else:
Messager.error('Unrecognized search match specification "%s"' % text_match)
return None
开发者ID:svigi,项目名称:brat-nlpg,代码行数:32,代码来源:search.py
示例2: _report_timings
def _report_timings(dbname, start, msg=None):
delta = datetime.now() - start
strdelta = str(delta).replace('0:00:0', '') # take out zero min & hour
queries = normdb.get_query_count(dbname)
normdb.reset_query_count(dbname)
Messager.info("Processed " + str(queries) + " queries in " + strdelta +
(msg if msg is not None else ""))
开发者ID:a-tsioh,项目名称:brat,代码行数:7,代码来源:norm.py
示例3: _server_crash
def _server_crash(cookie_hdrs, e):
from config import ADMIN_CONTACT_EMAIL, DEBUG
from jsonwrap import dumps
from message import Messager
stack_trace = _get_stack_trace()
if DEBUG:
# Send back the stack-trace as json
error_msg = '\n'.join(('Server Python crash, stack-trace is:\n',
stack_trace))
Messager.error(error_msg, duration=-1)
else:
# Give the user an error message
# Use the current time since epoch as an id for later log look-up
error_msg = ('The server encountered a serious error, '
'please contact the administrators at %s '
'and give the id #%d'
) % (ADMIN_CONTACT_EMAIL, int(time()))
Messager.error(error_msg, duration=-1)
# Print to stderr so that the exception is logged by the webserver
print(stack_trace, file=stderr)
json_dic = {
'exception': 'serverCrash',
}
return (cookie_hdrs, ((JSON_HDR, ), dumps(Messager.output_json(json_dic))))
开发者ID:a-tsioh,项目名称:brat,代码行数:28,代码来源:server.py
示例4: ann_logger
def ann_logger(directory):
"""
Lazy initializer for the annotation logger. Returns None if
annotation logging is not configured for the given directory and a
logger otherwise.
"""
if ann_logger.__logger == False:
# not initialized
annlogfile = options_get_annlogfile(directory)
if annlogfile == '<NONE>':
# not configured
ann_logger.__logger = None
else:
# initialize
try:
l = logging.getLogger('annotation')
l.setLevel(logging.INFO)
handler = logging.FileHandler(annlogfile)
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s\t%(message)s')
handler.setFormatter(formatter)
l.addHandler(handler)
ann_logger.__logger = l
except IOError, e:
Messager.error("""Error: failed to initialize annotation log %s: %s.
Edit action not logged.
Please check the Annotation-log logfile setting in tools.conf""" % (annlogfile, e))
logging.error("Failed to initialize annotation log %s: %s" %
(annlogfile, e))
ann_logger.__logger = None
开发者ID:AlexErmer,项目名称:CollaborativePDFAnnotation,代码行数:30,代码来源:annlog.py
示例5: ssdb_build
def ssdb_build(strs, dbname, ngram_length=DEFAULT_NGRAM_LENGTH, include_marks=DEFAULT_INCLUDE_MARKS):
"""
Given a list of strings, a DB name, and simstring options, builds
a simstring DB for the strings.
"""
try:
import simstring
except ImportError:
Messager.error(SIMSTRING_MISSING_ERROR, duration=-1)
raise NoSimStringError
dbfn = __ssdb_path(dbname)
try:
# only library defaults (n=3, no marks) supported just now (TODO)
assert ngram_length == 3, "Error: unsupported n-gram length"
assert include_marks == False, "Error: begin/end marks not supported"
db = simstring.writer(dbfn)
for s in strs:
db.insert(s)
db.close()
except:
print >> sys.stderr, "Error building simstring DB"
raise
return dbfn
开发者ID:Giovanni1085,项目名称:brat,代码行数:25,代码来源:simstringdb.py
示例6: norm_get_name
def norm_get_name(database, key, collection=None):
if NORM_LOOKUP_DEBUG:
_check_DB_version(database)
if REPORT_LOOKUP_TIMINGS:
lookup_start = datetime.now()
dbpath = _get_db_path(database, collection)
if dbpath is None:
# full path not configured, fall back on name as default
dbpath = database
try:
data = normdb.data_by_id(dbpath, key)
except normdb.dbNotFoundError as e:
Messager.warning(str(e))
data = None
# just grab the first one (sorry, this is a bit opaque)
if data is not None:
value = data[0][0][1]
else:
value = None
if REPORT_LOOKUP_TIMINGS:
_report_timings(database, lookup_start)
# echo request for sync
json_dic = {
'database': database,
'key': key,
'value': value
}
return json_dic
开发者ID:a-tsioh,项目名称:brat,代码行数:33,代码来源:norm.py
示例7: _config_check
def _config_check():
from message import Messager
from sys import path
from copy import deepcopy
from os.path import dirname
# Reset the path to force config.py to be in the root (could be hacked
# using __init__.py, but we can be monkey-patched anyway)
orig_path = deepcopy(path)
# Can't you empty in O(1) instead of O(N)?
while path:
path.pop()
path.append(path_join(abspath(dirname(__file__)), '../..'))
# Check if we have a config, otherwise whine
try:
import config
del config
except ImportError, e:
path.extend(orig_path)
# "Prettiest" way to check specific failure
if e.message == 'No module named config':
Messager.error(_miss_config_msg(), duration=-1)
else:
Messager.error(_get_stack_trace(), duration=-1)
raise ConfigurationError
开发者ID:TsujiiLaboratory,项目名称:stav,代码行数:25,代码来源:server.py
示例8: ssdb_supstring_exists
def ssdb_supstring_exists(s, dbname, threshold=DEFAULT_THRESHOLD):
"""Given a string s and a DB name, returns whether at least one string in
the associated simstring DB likely contains s as an (approximate)
substring."""
try:
import simstring
except ImportError:
Messager.error(SIMSTRING_MISSING_ERROR, duration=-1)
raise NoSimStringError
if threshold == 1.0:
# optimized (not hugely, though) for this common case
db = ssdb_open(dbname.encode('UTF-8'))
__set_db_measure(db, 'overlap')
db.threshold = threshold
result = db.retrieve(s)
db.close()
# assume simstring DBs always contain UTF-8 - encoded strings
result = [r.decode('UTF-8') for r in result]
for r in result:
if s in r:
return True
return False
else:
# naive implementation for everything else
return len(ssdb_supstring_lookup(s, dbname, threshold)) != 0
开发者ID:a-tsioh,项目名称:brat,代码行数:30,代码来源:simstringdb.py
示例9: retrieve_stored
def retrieve_stored(document, suffix):
stored_path = _stored_path()+'.'+suffix
if not isfile(stored_path):
# @ninjin: not sure what 'version' was supposed to be returned
# here, but none was defined, so returning that
# raise NoSVGError(version)
raise NoSVGError('None')
filename = document+'.'+suffix
# sorry, quick hack to get the content-type right
# TODO: send this with initial 'stored' response instead of
# guessing on suffix
if suffix == SVG_SUFFIX:
content_type = 'image/svg+xml'
elif suffix == PNG_SUFFIX:
content_type = 'image/png'
elif suffix == PDF_SUFFIX:
content_type = 'application/pdf'
elif suffix == EPS_SUFFIX:
content_type = 'application/postscript'
else:
Messager.error('Unknown suffix "%s"; cannot determine Content-Type' % suffix)
# TODO: reasonable backoff value
content_type = None
# Bail out with a hack since we violated the protocol
hdrs = [('Content-Type', content_type),
('Content-Disposition', 'inline; filename=' + filename)]
with open(stored_path, 'rb') as stored_file:
data = stored_file.read()
raise NoPrintJSONError(hdrs, data)
开发者ID:Rikard-Andersson,项目名称:GHTorrent-Brat,代码行数:35,代码来源:svg.py
示例10: possible_arc_types
def possible_arc_types(collection, origin_type, target_type):
directory = collection
real_dir = real_directory(directory)
projectconf = ProjectConfiguration(real_dir)
response = {}
try:
possible = projectconf.arc_types_from_to(origin_type, target_type)
# TODO: proper error handling
if possible is None:
Messager.error('Error selecting arc types!', -1)
elif possible == []:
# nothing to select
response['html'] = generate_empty_fieldset()
response['keymap'] = {}
response['empty'] = True
else:
# XXX TODO: intentionally breaking this; KB shortcuts
# should no longer be sent here. Remove 'keymap' and
# 'html' args once clientside generation done.
arc_kb_shortcuts = {} #select_keyboard_shortcuts(possible)
response['keymap'] = {}
for k, p in arc_kb_shortcuts.items():
response['keymap'][k] = "arc_"+p
response['html'] = generate_arc_type_html(projectconf, possible, arc_kb_shortcuts)
except:
Messager.error('Error selecting arc types!', -1)
raise
return response
开发者ID:pflaquerre,项目名称:brat,代码行数:34,代码来源:annotator.py
示例11: norm_get_data
def norm_get_data(database, key, collection=None):
if NORM_LOOKUP_DEBUG:
_check_DB_version(database)
if REPORT_LOOKUP_TIMINGS:
lookup_start = datetime.now()
dbpath = _get_db_path(database, collection)
if dbpath is None:
# full path not configured, fall back on name as default
dbpath = database
try:
data = normdb.data_by_id(dbpath, key)
except normdb.dbNotFoundError as e:
Messager.warning(str(e))
data = None
if data is None:
Messager.warning("Failed to get data for " + database + ":" + key)
if REPORT_LOOKUP_TIMINGS:
_report_timings(database, lookup_start)
# echo request for sync
json_dic = {
'database': database,
'key': key,
'value': data
}
return json_dic
开发者ID:a-tsioh,项目名称:brat,代码行数:30,代码来源:norm.py
示例12: _parse_relation_annotation
def _parse_relation_annotation(self, id, data, data_tail, input_file_path):
try:
type_delim = data.index(' ')
type, type_tail = (data[:type_delim], data[type_delim:])
except ValueError:
# cannot have a relation with just a type (contra event)
raise IdedAnnotationLineSyntaxError(id, self.ann_line, self.ann_line_num+1, input_file_path)
try:
args = [tuple(arg.split(':')) for arg in type_tail.split()]
except ValueError:
raise IdedAnnotationLineSyntaxError(id, self.ann_line, self.ann_line_num+1, input_file_path)
if len(args) != 2:
Messager.error('Error parsing relation: must have exactly two arguments')
raise IdedAnnotationLineSyntaxError(id, self.ann_line, self.ann_line_num+1, input_file_path)
args.sort()
if args[0][0] == args[1][0]:
Messager.error('Error parsing relation: arguments must not be identical')
raise IdedAnnotationLineSyntaxError(id, self.ann_line, self.ann_line_num+1, input_file_path)
return BinaryRelationAnnotation(id, type,
args[0][0], args[0][1],
args[1][0], args[1][1],
data_tail, source_id=input_file_path)
开发者ID:TsujiiLaboratory,项目名称:stav,代码行数:26,代码来源:annotation.py
示例13: get_drawing_config_by_storage_form
def get_drawing_config_by_storage_form(directory, term):
cache = get_drawing_config_by_storage_form.__cache
if directory not in cache:
d = {}
for n in get_drawing_config(directory):
t = n.storage_form()
if t in d:
Messager.warning("Project configuration: term %s appears multiple times, only using last. Configuration may be wrong." % t, 5)
d[t] = {}
for a in n.arguments:
if len(n.arguments[a]) != 1:
Messager.warning("Project configuration: expected single value for %s argument %s, got '%s'. Configuration may be wrong." % (t, a, "|".join(n.arguments[a])))
else:
d[t][a] = n.arguments[a][0]
# TODO: hack to get around inability to have commas in values;
# fix original issue instead
for t in d:
for k in d[t]:
d[t][k] = d[t][k].replace("-", ",")
# propagate defaults (TODO: get rid of magic "DEFAULT" values)
default_keys = [VISUAL_SPAN_DEFAULT, VISUAL_ARC_DEFAULT]
for default_dict in [d.get(dk, {}) for dk in default_keys]:
for k in default_dict:
for t in d:
d[t][k] = d[t].get(k, default_dict[k])
cache[directory] = d
return cache[directory].get(term, None)
开发者ID:TsujiiLaboratory,项目名称:stav,代码行数:31,代码来源:projectconfig.py
示例14: arc_types_from_to
def arc_types_from_to(self, from_ann, to_ann="<ANY>", include_special=False):
"""
Returns the possible arc types that can connect an annotation
of type from_ann to an annotation of type to_ann.
If to_ann has the value \"<ANY>\", returns all possible arc types.
"""
from_node = get_node_by_storage_form(self.directory, from_ann)
if from_node is None:
Messager.warning("Project configuration: unknown textbound/event type %s. Configuration may be wrong." % from_ann)
return []
if to_ann == "<ANY>":
relations_from = get_relations_by_arg1(self.directory, from_ann, include_special)
# TODO: consider using from_node.arg_list instead of .arguments for order
return unique_preserve_order([role for role in from_node.arguments] + [r.storage_form() for r in relations_from])
# specific hits
types = from_node.keys_by_type.get(to_ann, [])
if "<ANY>" in from_node.keys_by_type:
types += from_node.keys_by_type["<ANY>"]
# generic arguments
if self.is_event_type(to_ann) and '<EVENT>' in from_node.keys_by_type:
types += from_node.keys_by_type['<EVENT>']
if self.is_physical_entity_type(to_ann) and '<ENTITY>' in from_node.keys_by_type:
types += from_node.keys_by_type['<ENTITY>']
# relations
types.extend(self.relation_types_from_to(from_ann, to_ann))
return unique_preserve_order(types)
开发者ID:TsujiiLaboratory,项目名称:stav,代码行数:34,代码来源:projectconfig.py
示例15: ann_logger
def ann_logger():
"""
Lazy initializer for the annotation logger. Returns None if
annotation logging is not configured and a logger otherwise.
"""
if ann_logger.__logger == False:
# not initialized
if ANNOTATION_LOG is None:
# not configured
ann_logger.__logger = None
else:
# initialize
try:
l = logging.getLogger('annotation')
l.setLevel(logging.INFO)
handler = logging.FileHandler(ANNOTATION_LOG)
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s\t%(message)s')
handler.setFormatter(formatter)
l.addHandler(handler)
ann_logger.__logger = l
except IOError, e:
Messager.error("""Error: failed to initialize annotation log %s: %s.
Edit action not logged.
Please check ANNOTATION_LOG setting in config.py""" % (ANNOTATION_LOG, e))
logging.error("Failed to initialize annotation log %s: %s" %
(ANNOTATION_LOG, e))
ann_logger.__logger = None
开发者ID:TsujiiLaboratory,项目名称:brat,代码行数:28,代码来源:annlog.py
示例16: _parse_attributes
def _parse_attributes(attributes):
if attributes is None:
_attributes = {}
else:
try:
_attributes = json_loads(attributes)
except ValueError:
# Failed to parse, warn the client
Messager.warning(
('Unable to parse attributes string "%s" for '
'"createSpan", ignoring attributes for request and '
'assuming no attributes set') %
(attributes, ))
_attributes = {}
# XXX: Hack since the client is sending back False and True as values...
# These are __not__ to be sent, they violate the protocol
for _del in [k for k, v in list(_attributes.items()) if v == False]:
del _attributes[_del]
# These are to be old-style modifiers without values
for _revalue in [k for k, v in list(_attributes.items()) if v]:
_attributes[_revalue] = True
###
return _attributes
开发者ID:a-tsioh,项目名称:brat,代码行数:25,代码来源:annotator.py
示例17: login
def login(user, password):
if not _is_authenticated(user, password):
raise InvalidAuthError
get_session()['user'] = user
Messager.info('Hello!')
return {}
开发者ID:AlexErmer,项目名称:CollaborativePDFAnnotation,代码行数:7,代码来源:auth.py
示例18: filter_folia
def filter_folia(ann_obj):
forbidden_ann=[]
response = {"entities":[],"comments":[],"relations":[],"attributes":[],"tokens":{}}
try:
import simplejson as json
import session
string = session.load_conf()["config"]
val = json.loads(string)["foliaLayers"]
except session.NoSessionError:
val = []
except KeyError:
val = []
pass
except Exception as e:
val = []
Messager.error("Error while enabling/disabling folia layers: "+str(e))
pass
try:
response["tokens"]=ann_obj.folia["tokens"]
except KeyError as e:
pass
if val:
removed = set()
forbidden = set(i for i in val)
result = []
alternatives = "alter" in val
try:
if 'all' in val:
response["tokens"]={}
return response
else:
for i in ann_obj.folia["entities"]:
if not i[3] in forbidden and not ( i[4] and alternatives ):
result.append(i)
else:
removed.add(i[0])
response["entities"] = result
result = []
for i in ann_obj.folia["relations"]:
if not i[3] in forbidden and not i[2][0][1] in removed and not i[2][1][1] in removed and not ( i[4] and alternatives ):
result.append(i)
else:
removed.add(i[0])
response["relations"] = result
result = []
for i in ann_obj.folia["attributes"]:
if not i[2] in removed:
result.append(i)
response["attributes"] = result
result = []
for i in ann_obj.folia["comments"]:
if not i[0] in removed:
result.append(i)
response["comments"] = result
except KeyError:
pass
else:
response = ann_obj.folia
return response
开发者ID:proycon,项目名称:brat,代码行数:59,代码来源:ApplicationScope.py
示例19: __read_term_hierarchy
def __read_term_hierarchy(input):
root_nodes = []
last_node_at_depth = {}
macros = {}
for l in input:
# skip empties and lines starting with '#'
if l.strip() == '' or re.match(r'^\s*#', l):
continue
# interpret lines of only hyphens as separators
# for display
if re.match(r'^\s*-+\s*$', l):
# TODO: proper placeholder and placing
root_nodes.append(SEPARATOR_STR)
continue
# interpret lines of the format <STR1>=STR2 as "macro"
# definitions, defining <STR1> as a placeholder that should be
# replaced with STR2 whevever it occurs.
m = re.match(r'^<([a-zA-Z_-]+)>=\s*(.*?)\s*$', l)
if m:
name, value = m.groups()
if name in reserved_macro_name:
Messager.error("Cannot redefine <%s> in configuration, it is a reserved name." % name)
# TODO: proper exception
assert False
else:
macros["<%s>" % name] = value
continue
# macro expansion
for n in macros:
l = l.replace(n, macros[n])
m = re.match(r'^(\s*)([^\t]+)(?:\t(.*))?$', l)
assert m, "Error parsing line: '%s'" % l
indent, terms, args = m.groups()
terms = [t.strip() for t in terms.split("|") if t.strip() != ""]
if args is None or args.strip() == "":
args = []
else:
args = [a.strip() for a in args.split(",") if a.strip() != ""]
# depth in the ontology corresponds to the number of
# spaces in the initial indent.
depth = len(indent)
n = TypeHierarchyNode(terms, args)
if depth == 0:
# root level, no children assignments
root_nodes.append(n)
else:
# assign as child of last node at the depth of the parent
assert depth-1 in last_node_at_depth, "Error: no parent for '%s'" % l
last_node_at_depth[depth-1].children.append(n)
last_node_at_depth[depth] = n
return root_nodes
开发者ID:TsujiiLaboratory,项目名称:stav,代码行数:59,代码来源:projectconfig.py
示例20: _safe_serve
def _safe_serve(params, client_ip, client_hostname, cookie_data):
# Note: Only logging imports here
from config import WORK_DIR
from logging import basicConfig as log_basic_config
# Enable logging
try:
from config import LOG_LEVEL
log_level = _convert_log_level(LOG_LEVEL)
except ImportError:
from logging import WARNING as LOG_LEVEL_WARNING
log_level = LOG_LEVEL_WARNING
log_basic_config(filename=path_join(WORK_DIR, "server.log"), level=log_level)
# Do the necessary imports after enabling the logging, order critical
try:
from common import ProtocolError, ProtocolArgumentError, NoPrintJSONError
from dispatch import dispatch
from jsonwrap import dumps
from message import Messager
from session import get_session, init_session, close_session, NoSessionError, SessionStoreError
except ImportError:
# Note: Heisenbug trap for #612, remove after resolved
from logging import critical as log_critical
from sys import path as sys_path
log_critical("Heisenbug trap reports: " + str(sys_path))
raise
init_session(client_ip, cookie_data=cookie_data)
response_is_JSON = True
try:
# Unpack the arguments into something less obscure than the
# Python FieldStorage object (part dictonary, part list, part FUBAR)
http_args = DefaultNoneDict()
for k in params:
# Also take the opportunity to convert Strings into Unicode,
# according to HTTP they should be UTF-8
try:
http_args[k] = unicode(params.getvalue(k), encoding="utf-8")
except TypeError:
Messager.error(
"protocol argument error: expected string argument %s, got %s" % (k, type(params.getvalue(k)))
)
raise ProtocolArgumentError
# Dispatch the request
json_dic = dispatch(http_args, client_ip, client_hostname)
except ProtocolError, e:
# Internal error, only reported to client not to log
json_dic = {}
e.json(json_dic)
# Add a human-readable version of the error
err_str = str(e)
if err_str != "":
Messager.error(err_str, duration=-1)
开发者ID:Giovanni1085,项目名称:brat,代码行数:59,代码来源:server.py
注:本文中的message.Messager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论