python_code stringlengths 0 187k | repo_name stringlengths 8 46 | file_path stringlengths 6 135 |
|---|---|---|
#!/usr/bin/env python
# Script to convert a CoNLL X (2006) tabbed dependency tree format
# file into BioNLP ST-flavored standoff and a reconstruction of the
# original text.
from __future__ import with_statement
import sys
import re
import os
import codecs
# maximum number of sentences to include in single output d... | brat-master | tools/conllXtostandoff.py |
#!/usr/bin/env python
'''
Basic sentence splitter using brat segmentation to add newlines to
input text at likely sentence boundaries.
'''
import sys
from os.path import join as path_join
from os.path import dirname
# Assuming this script is found in the brat tools/ directory ...
from sys import path as sys_path
sys... | brat-master | tools/sentencesplit.py |
#!/usr/bin/env python
'''
Attempt to diagnose common problems with the brat server by using HTTP.
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2012-05-22
'''
from httplib import HTTPConnection, HTTPSConnection
from httplib import FORBIDDEN, MOVED_PERMANENTLY, NOT_FOUND, OK, TEMPORARY_REDIRECT
fr... | brat-master | tools/troubleshooting.py |
#!/usr/bin/env python
'''
A very simple tokenization service.
'''
import re
from argparse import ArgumentParser
from cgi import FieldStorage
try:
from json import dumps
except ImportError:
# likely old Python; try to fall back on ujson in brat distrib
from sys import path as sys_path
from os.path im... | brat-master | tools/tokenservice.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
# Special-purpose script for rewriting a specific entity annotation
# type as an event. Can be useful if an annotation project has started
# out representing an annotation o... | brat-master | tools/ent2event.py |
#!/usr/bin/env python
'''
Generate the offline_data directory contents.
HACKY and NOT OFFLINE, but needed for testing at least.
TODO: rewrite properly, without going through the net.
Usage: tools/offlinearize <url-to-top-collection>
TODO behaviour:
* Start with root collection and recurse
* Put the result of ge... | brat-master | tools/offlinearize.py |
#!/usr/bin/env python
# "Normalizes" IDs in brat-flavored standoff so that the first "T" ID
# is "T1", the second "T2", and so on, for all ID prefixes.
from __future__ import with_statement
import sys
import re
DEBUG = True
class Annotation(object):
def __init__(self, id_, type_):
self.id_ = id_
... | brat-master | tools/idnorm.py |
#!/usr/bin/env python
# Given a set of brat-flavored standoff .ann files, catenates them
# into a single .ann file (with reference to the corresponding .txt
# files) so that the resulting .ann applies for the simple catenation
# of the .txt files.
from __future__ import with_statement
import sys
import re
import os
... | brat-master | tools/catann.py |
#!/usr/bin/env python
'''
Generate a set of colours for a given set of input labels.
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2012-06-28
'''
# TODO: With some frequency information this could be done even more
# intelligently, attempting to use the space optimally by keeping frequent
# l... | brat-master | tools/colourise.py |
#!/usr/bin/env python
import sys
import re
try:
import cElementTree as ET
except:
import xml.etree.cElementTree as ET
# tags of elements to exclude from standoff output
# (not used now; anything not explicitly converted is excluded)
EXCLUDED_TAGS = [
# "SP",
# "IT",
# "SB",
# "REF",
# "P",... | brat-master | tools/coresctostandoff.py |
#!/usr/bin/env python
# Test script for lookup in a normalization SQL DB, intended for
# DB testing.
# TODO: duplicates parts of primary norm DB implementation, dedup.
import sys
import os.path
import sqlite3 as sqlite
TYPE_TABLES = ["names", "attributes", "infos"]
NON_EMPTY_TABLES = set(["names"])
def argparser()... | brat-master | tools/norm_db_lookup.py |
#!/usr/bin/env python
# Align text and annotations to a different version of the same text.
# Note: not comprehensively tested, use with caution.
from __future__ import with_statement
import sys
import re
import codecs
# import numpy
DEFAULT_ENCODING = 'UTF-8'
TEST_ARG = '--test'
DEBUG=False
WARN_LENGTH_PRODUCT... | brat-master | tools/annalign.py |
#!/usr/bin/env python
import sys
import re
try:
import cElementTree as ET
except:
import xml.etree.cElementTree as ET
# tags of elements to exclude from standoff output
EXCLUDED_TAGS = [
"SURNAME",
"AUTHOR",
"REFERENCE",
"AUTHORLIST",
"JOURNAL",
"YEAR",
"P",
"TITLE",
"DIV",... | brat-master | tools/aziitostandoff.py |
#!/usr/bin/env python
# Converts the BioCreative 2 Gene Mention task data into brat-flavored
# standoff format.
from __future__ import with_statement
import sys
import re
import os
def char_offsets(text, start, end, ttext):
# Given a text and a tagged span marked by start and end offsets
# ignoring space (p... | brat-master | tools/BC2GMtoStandoff.py |
#!/usr/bin/env python
# Creates SQL and simstring DBs for brat normalization support.
# Each line in the input file should have the following format:
# ID<TAB>TYPE1:LABEL1:STRING1<TAB>TYPE2:LABEL2:STRING2[...]
# Where the ID is the unique ID normalized to, and the
# TYPE:LABEL:STRING triplets provide various inform... | brat-master | tools/norm_db_init.py |
#!/usr/bin/env python
# Remove portions of text from annotated files.
# Note: not comprehensively tested, use with caution.
from __future__ import with_statement
import sys
import re
try:
import argparse
except ImportError:
from os.path import basename
from sys import path as sys_path
# We are most... | brat-master | tools/anncut.py |
#!/usr/bin/env python
# Special-purpose script for converting the NCBI disease corpus into a
# format recognized by brat.
# The NCBI disease corpus is distributed in a line-oriented format, each
# consisting of tab-separated triples (PMID, title, text). Annotations
# are inline in pseudo-XML, e.g.
# <category="S... | brat-master | tools/convert-NCBI-disease.py |
#!/usr/bin/env python
# Script to convert a CoNLL 2000-flavored BIO-formatted entity-tagged
# file into BioNLP ST-flavored standoff and a reconstruction of the
# original text.
from __future__ import with_statement
import sys
import re
import os
import codecs
INPUT_ENCODING = "ASCII"
OUTPUT_ENCODING = "UTF-8"
outp... | brat-master | tools/conll00tostandoff.py |
#!/usr/bin/env python
# Special-purpose script for converting the NCBI taxonomy data dump
# into the brat normalization DB input format
# (http://brat.nlplab.org/normalization.html).
# The script expects as input the names.dmp file available from
# the NCBI FTP site (ftp://ftp.ncbi.nih.gov/pub/taxonomy/).
# As of lat... | brat-master | tools/convert-NCBITaxon.py |
#!/usr/bin/evn python
# Script for converting Entrez Gene data into the brat normalization
# DB input format (http://brat.nlplab.org/normalization.html).
# The script expects as input the gene_info file available from the
# NCBI FTP site (ftp://ftp.ncbi.nih.gov/gene/DATA/).
# The gene_info file format is TAB-separat... | brat-master | tools/convert-EntrezGene.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
# Generates a web pages linking to visualizations of each document in
# a BioNLP ST 2011 Shared Task dataset.
import sys
import os
try:
import argparse
except ImportEr... | brat-master | tools/generate-static.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
from __future__ import with_statement
'''
Split merged BioNLP Shared Task annotations into separate files.
Author: Sampo Pyysalo
Version: 2011-02-24
'''
import sys... | brat-master | tools/unmerge.py |
#!/usr/bin/env python
# Convert text and standoff annotations into CoNLL format.
from __future__ import with_statement
import sys
import re
import os
from collections import namedtuple
from os import path
from subprocess import Popen, PIPE
from cStringIO import StringIO
# assume script in brat tools/ directory, ex... | brat-master | tools/anntoconll.py |
#!/usr/bin/env python
# Basic support for extracting data from .obo ontology files.
# Adapted from readobo.py in sols.
# TODO: replace with a proper lib.
import sys
import re
from string import lowercase
options = None
def case_normalize_initial(s):
# to avoid lowercasing first letter of e.g. abbrevs, require ... | brat-master | tools/oboextract.py |
#!/usr/bin/env python
'''
Convert Malt dependencies to CoNLL-X dependencies.
Usage:
cat *.malt | ./malt2connlX.py > output.conll
NOTE: Beware of nasty Windows newlines:
dos2unix *.malt
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2011-12-05
'''
from sys import stdin, stdout
from re i... | brat-master | tools/malt2connlX.py |
#!/usr/bin/env python
"""An example of a tagging service using RESTful Open Annotation."""
import sys
import logging
import requests
import re
from logging import info, warn
from json import dumps
from cgi import FieldStorage
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
TAGGER_URI = 'http://tagger... | brat-master | tools/restoataggerservice.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
# Preamble {{{
from __future__ import with_statement
'''
Mark the differences between two annotation files, creating a diff annotation
'''
try:
import annotation
exce... | brat-master | tools/diff_and_mark.py |
#!/usr/bin/env python
'''
Using pexpect to interact with CoreNLP.
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2012-04-18
'''
from os import listdir
from os.path import isdir, join as path_join
from re import compile as re_compile, match
# I am not a huge fan of pexpect, but it will get the job... | brat-master | tools/corenlpnertaggerservice/corenlp.py |
#!/usr/bin/env python
'''
Simple tagger service using CoreNLP.
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2012-04-18
'''
from argparse import ArgumentParser
from cgi import FieldStorage
from os.path import dirname, join as path_join
from corenlp import CoreNLPTagger
try:
from json import... | brat-master | tools/corenlpnertaggerservice/corenlptaggerservice.py |
from operator import itemgetter as _itemgetter
from keyword import iskeyword as _iskeyword
import sys as _sys
# namedtyple implementation for older pythons, from
# http://code.activestate.com/recipes/500261/
def namedtuple(typename, field_names, verbose=False, rename=False):
"""Returns a new subclass of tuple wit... | brat-master | server/lib/altnamedtuple.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8 -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
# Copyright © 2006-2009 Steven J. Bethard <steven.bethard@gmail.com>.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except i... | brat-master | server/lib/argparse.py |
#!/usr/bin/env python
# Python version of geniass-postproc.pl. Originally developed as a
# heuristic postprocessor for the geniass sentence splitter, drawing
# in part on Yoshimasa Tsuruoka's medss.pl.
from __future__ import with_statement
import re
INPUT_ENCODING = "UTF-8"
OUTPUT_ENCODING = "UTF-8"
DEBUG_SS_POSTPR... | brat-master | server/src/sspostproc.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Deletion functionality.
'''
from __future__ import with_statement
from os.path import join as path_join
from message import Messager
def delete_document(collection, d... | brat-master | server/src/delete.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Authentication and authorization mechanisms.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Illes Solt <solt tmit bme hu>
Version: ... | brat-master | server/src/auth.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
from __future__ import with_statement
'''
Functionality related to the annotation file format.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Version: 2011-... | brat-master | server/src/annotation.py |
#!/usr/bin/env python
from __future__ import with_statement
'''
Back-up mechanisms for the data directory.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Version: 2011-02-22
'''
#XXX: We can potentially miss a change within the same second as the back-up,
# we need to share a mutex with the re... | brat-master | server/src/backup.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Main entry for the brat server, ensures integrity, handles dispatch and
processes potential exceptions before returning them to be sent as responses.
NOTE(S):
* Defer imports until ... | brat-master | server/src/server.py |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import with_statement
'''
Tokenisation related functionality.
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2011-05-23
'''
from os.path import join as path_join
from os.path import dirname
from subprocess import Popen, PIPE
from shlex im... | brat-master | server/src/tokenise.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Functionality for normalization SQL database access.
'''
import sys
from os.path import join as path_join, exists, sep as path_sep
import sqlite3 as sqlite
try:
fr... | brat-master | server/src/normdb.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Server request dispatching mechanism.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Version: 2011-04-21
'''
from os.path import abspath, normpath
from... | brat-master | server/src/dispatch.py |
#!/usr/bin/env python
from __future__ import with_statement
'''
Simple interface to for importing files into the data directory.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Version: 2011-02-21
'''
from annotation import open_textfile
from common import ProtocolError
from config import DATA_DIR
fr... | brat-master | server/src/docimport.py |
#!/usr/bin/env python
'''
Grammar for the brat stand-off format.
Example, test grammar on a collection:
find . -name '*.ann' | parallel cat | ./bratyacc.py
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2011-07-11
'''
try:
import ply.yacc as yacc
except ImportError:
# We need to add ply ... | brat-master | server/src/bratyacc.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Normalization support.
'''
import normdb
import simstringdb
import sdistance
from datetime import datetime
from message import Messager
from normdb import string_norm_... | brat-master | server/src/norm.py |
'''
Serves annotation related files for downloads.
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2011-10-03
'''
from __future__ import with_statement
from os import close as os_close, remove
from os.path import join as path_join, dirname, basename, normpath
from tempfile import mkstemp
from docu... | brat-master | server/src/download.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Prediction for annotation types.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Author: Sampo Pyysalo <smp is s u-tokyo ac jp>
Version: 2011-1... | brat-master | server/src/predict.py |
#!/usr/bin/env python
# -*- coding: utf-8 -*-`
'''
MeCab wrapper for brat
http://mecab.sourceforge.net/
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2011-05-17
'''
from os.path import dirname
from os.path import join as path_join
from re import compile as re_compile
from re import DOTALL
### Cons... | brat-master | server/src/mecab.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Session handling class.
Note: New modified version using pickle instead of shelve.
Author: Goran Topic <goran is s u-tokyo ac jp>
Author: Pontus Stenet... | brat-master | server/src/session.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Annotator functionality, editing and retrieving status.
Author: Pontus Stenetorp
Version: 2011-04-22
'''
# XXX: This module is messy, re-factor to be done
from... | brat-master | server/src/annotator.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Wrapper for safely importing Messager with a fallback that will
get _something_ to the user even if Messager itself breaks.
'''
try:
from realmessage import Message... | brat-master | server/src/message.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
# Verification of BioNLP Shared Task - style annotations.
from __future__ import with_statement
import annotation
from projectconfig import ProjectConfiguration
# Issue ... | brat-master | server/src/verify_annotations.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Per-project configuration functionality for
Brat Rapid Annotation Tool (brat)
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Author: Sampo Pyysalo ... | brat-master | server/src/projectconfig.py |
#!/usr/bin/env python
from __future__ import with_statement
'''
Provides a stylish pythonic file-lock:
>>> with('file.lock'):
... pass
Inspired by: http://code.activestate.com/recipes/576572/
Is *NIX specific due to being forced to use ps (suggestions on how to avoid
this are welcome).
But with added ti... | brat-master | server/src/filelock.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
# Implements a GENIA Treebank - like tokenization.
# This is a python translation of my GTB-tokenize.pl, which in turn
# draws in part on Robert MacIntyre's 1995 PTB token... | brat-master | server/src/gtbtokenize.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Functionality shared between server components.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Version: 2011-04-21
'''
class ProtocolError(Exception):... | brat-master | server/src/common.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
SVG saving and storage functionality.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Author: Goran Topic <goran is s u-tokyo ac jp>
Version: ... | brat-master | server/src/svg.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Server-to-client messaging-related functionality
for Brat Rapid Annotation Tool (brat)
NOTE: This module is used by ajax.cgi prior to verifying that the Python
version ... | brat-master | server/src/realmessage.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
from __future__ import with_statement
'''
Annotation statistics generation.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Version: 2011-04-21
'''
from cP... | brat-master | server/src/stats.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
# XXX: This module along with stats and annotator is pretty much pure chaos
from __future__ import with_statement
'''
Document handling functionality.
Author: Pontus ... | brat-master | server/src/document.py |
#!/usr/bin/env python
'''
Various string distance measures.
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2011-08-09
'''
from string import digits, lowercase
from sys import maxint
DIGITS = set(digits)
LOWERCASE = set(lowercase)
TSURUOKA_2004_INS_CHEAP = set((' ', '-', ))
TSURUOKA_2004_DEL_CHEAP... | brat-master | server/src/sdistance.py |
#!/usr/bin/env python
'''
Annotation undo functionality.
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2011-11-30
'''
from __future__ import with_statement
from os.path import join as path_join
from annotator import delete_span, create_span
from annotation import TextAnnotations
from common imp... | brat-master | server/src/undo.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Dummy Messager that can replace the real one in case it goes down.
Doesn't actually send any messages other than letting the user
know of the problem.
Use e.g. as
t... | brat-master | server/src/sosmessage.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Annotation operation logging mechanism.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Author: Sampo Pyysalo <smp is s u-tokyo ac jp>
Version: ... | brat-master | server/src/annlog.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
# Search-related functionality for BioNLP Shared Task - style
# annotations.
from __future__ import with_statement
import re
import annotation
from message import Message... | brat-master | server/src/search.py |
#!/usr/bin/env python
import glob
import os
import sys
from common import ProtocolError
from message import Messager
from os.path import join as path_join, sep as path_sep
try:
from config import BASE_DIR, WORK_DIR
except ImportError:
# for CLI use; assume we're in brat server/src/ and config is in root
... | brat-master | server/src/simstringdb.py |
'''
json wrapper to be used instead of a direct call.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Version: 2011-04-21
'''
# use ultrajson if set up
try:
from sys import path as sys_path
from os.path import join as path_join
from os.path import dirname
sys_path.append(path_join(dirn... | brat-master | server/src/jsonwrap.py |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import with_statement
'''
Primitive sentence splitting using Sampo Pyysalo's GeniaSS sentence split
refiner. Also a primitive Japanese sentence splitter without refinement.
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2011-05-09
'''
fro... | brat-master | server/src/ssplit.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Functionality for invoking tagging services.
Author: Pontus Stenetorp
Version: 2011-04-22
'''
from __future__ import with_statement
from httplib import HTTPCon... | brat-master | server/src/tag.py |
#!/usr/bin/env python
'''
Tokenisation for the brat stand-off format.
Example, test tokenisation on a collection:
find . -name '*.ann' | parallel cat | ./bratlex.py
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2011-07-11
'''
try:
import ply.lex as lex
except ImportError:
# We need to add... | brat-master | server/src/bratlex.py |
'''
Conversion services, we may want to move these out later on.
Author: Pontus Stenetorp <pontus stenetorp>
Version: 2012-06-26
'''
from __future__ import with_statement
from os.path import join as path_join
from shutil import rmtree
from tempfile import mkdtemp
from annotation import open_textfile, Anno... | brat-master | server/src/convert/convert.py |
brat-master | server/src/convert/__init__.py | |
#!/usr/bin/env python
'''
Conversion scripts related to Stanford tools.
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2012-06-26
'''
# TODO: Currently pretty much every single call re-parses the XML, optimise?
# TODO: We could potentially put the lemma into a comment
from __future__ import with_... | brat-master | server/src/convert/stanford.py |
#!/usr/bin/env python
'''
Penn TreeBank escaping.
Author: Pontus Stenetorp <pontus stenetorp se>
Version: 2011-09-12
'''
### Constants
# From: To
PTB_ESCAPES = {
u'(': u'-LRB-',
u')': u'-RRB-',
u'[': u'-LSB-',
u']': u'-RSB-',
u'{': u'-LCB-',
u'}': u'-RCB-',
... | brat-master | server/src/convert/ptbesc.py |
#!/usr/bin/env python3
# 0-*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
import sys
import os.path
import itertools
import glob
import re
import codecs
import logging
import en_core_web_md
if "." in __name__:
from . import annotation
else:
import annotation
class EnhancedAnnotated... | brat-master | ai2_brat/ai2_common.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
from __future__ import with_statement
'''
Functionality related to the annotation file format.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Version: 2011-... | brat-master | ai2_brat/annotation.py |
#!/usr/bin/env python3
# 0-*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
import argparse
import ai2_common
import itertools
import sys
import annotation
def find_discontinuous(text_annotation):
return [e for e in text_annotation.get_entities() if len(e.spans) > 1]
def find_overlappin... | brat-master | ai2_brat/find_problematic_annotations.py |
brat-master | ai2_brat/__init__.py | |
#!/usr/bin/env python
from __future__ import with_statement
'''
Provides a stylish pythonic file-lock:
>>> with('file.lock'):
... pass
Inspired by: http://code.activestate.com/recipes/576572/
Is *NIX specific due to being forced to use ps (suggestions on how to avoid
this are welcome).
But with added ti... | brat-master | ai2_brat/filelock.py |
#!/usr/bin/env python3
# 0-*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
import argparse
import logging
import re
import os
import os.path
if "." in __name__:
from . import ai2_common
else:
import ai2_common
def remove_discontinuous_entities(doc):
to_remove = [e for e in doc.e... | brat-master | ai2_brat/fixup_annotations.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Functionality shared between server components.
Author: Pontus Stenetorp <pontus is s u-tokyo ac jp>
Version: 2011-04-21
'''
class ProtocolError(Exception):... | brat-master | ai2_brat/common.py |
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# vim:set ft=python ts=4 sw=4 sts=4 autoindent:
'''
Server-to-client messaging-related functionality
for Brat Rapid Annotation Tool (brat)
NOTE: This module is used by ajax.cgi prior to verifying that the Python
version ... | brat-master | ai2_brat/realmessage.py |
#!/usr/bin/env python3
# 0-*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
import ai2_common
import argparse
import copy
import locale
import logging
import itertools
import codecs
import os.path
import sys
from shutil import copyfile
from collections import defaultdict
import annotation
def... | brat-master | ai2_brat/merge_annotations.py |
#!/usr/bin/env python3
# 0-*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*-
import ai2_common
import numpy as np
import argparse
import itertools
import re
from scipy import stats
from collections import defaultdict
from functools import reduce
'''
Compute inter-annotator agreement
'''
class ... | brat-master | ai2_brat/measure_agreement.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""Composer package setup."""
import os
import site
import sys
import textwrap
import setuptools
from setuptools import setup
from setuptools.command.develop import develop as develop_orig
# Read the composer version
# Cannot import fr... | composer-dev | setup.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""Helper script to generate the ``build_matrix.yaml`` and update ``README.md``.
Note: this script requires tabulate. Run ``pip install tabulate`` if not installed
To run::
python generate_build_matrix.py
"""
import itertools
impo... | composer-dev | docker/generate_build_matrix.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""Setup script for the stub pillow."""
import os
from setuptools import setup
setup(
name='pillow',
version=os.environ['PILLOW_PSEUDOVERSION'],
)
| composer-dev | docker/pillow_stub/setup.py |
import os
print("World Size", os.environ["WORLD_SIZE"])
| composer-dev | .ci/release_tests/print_world_size.py |
import composer.functional as cf
from torchvision import models
my_model = models.resnet18()
# add blurpool and squeeze excite layers
cf.apply_blurpool(my_model)
cf.apply_squeeze_excite(my_model)
# your own training code starts here
| composer-dev | .ci/release_tests/example_1.py |
import torch
# adaptive_avg_pool2d_backward_cuda in mnist_classifier is not deterministic
torch.use_deterministic_algorithms(False)
from torch.utils.data import DataLoader
from torchvision import datasets, transforms
from composer import Trainer
from composer.algorithms import ChannelsLast, CutMix, LabelSmoothing
fr... | composer-dev | .ci/release_tests/example_2.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""The Composer Version."""
__version__ = '0.13.2'
| composer-dev | composer/_version.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""Some key classes are available directly in the ``composer`` namespace."""
from composer._version import __version__
from composer.core import Algorithm, Callback, DataSpec, Engine, Evaluator, Event, State, Time, Timestamp, TimeUnit
fr... | composer-dev | composer/__init__.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""Runs the Composer CLI."""
from composer.cli import __main__
| composer-dev | composer/__main__.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""A collection of common torchmetrics."""
from __future__ import annotations
from typing import Callable, Tuple
import torch
from torch import Tensor
from torchmetrics import Metric
from torchmetrics.utilities.data import to_categorica... | composer-dev | composer/metrics/metrics.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""A collection of common torchmetrics."""
from composer.metrics.map import MAP
from composer.metrics.metrics import CrossEntropy, Dice, LossMetric, MIoU
from composer.metrics.nlp import (BinaryF1Score, HFCrossEntropy, InContextLearningL... | composer-dev | composer/metrics/__init__.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
# Adapted from https://github.com/Lightning-AI/metrics/blob/1c42f6643f9241089e55a4d899f14da480021e16/torchmetrics/detection/map.py
# Current versions of MAP in torchmetrics are incorrect or slow as of 9/21/22.
# Relevant issues:
# https:/... | composer-dev | composer/metrics/map.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""A collection of common torchmetrics for NLP tasks."""
import re
import string
import warnings
from typing import List, Mapping, Optional, Union
import torch
from torch import Tensor
from torch.nn import functional as F
from torchmetri... | composer-dev | composer/metrics/nlp.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""Log to `MLFlow <https://www.mlflow.org/docs/latest/index.html>."""
from __future__ import annotations
import pathlib
from typing import Any, Dict, Optional, Union
from composer.core.state import State
from composer.loggers.logger im... | composer-dev | composer/loggers/mlflow_logger.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""Log to `Tensorboard <https://www.tensorflow.org/tensorboard/>`_."""
from pathlib import Path
from typing import Any, Dict, Optional
from composer.core.state import State
from composer.loggers.logger import Logger, format_log_data_val... | composer-dev | composer/loggers/tensorboard_logger.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""Logs metrics to dictionary objects that persist in memory throughout training.
Useful for collecting and plotting data inside notebooks.
"""
from __future__ import annotations
import copy
from typing import TYPE_CHECKING, Any, Dict,... | composer-dev | composer/loggers/in_memory_logger.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""Log to `Weights and Biases <https://wandb.ai/>`_."""
from __future__ import annotations
import atexit
import copy
import os
import pathlib
import re
import sys
import tempfile
import textwrap
import warnings
from typing import TYPE_C... | composer-dev | composer/loggers/wandb_logger.py |
# Copyright 2022 MosaicML Composer authors
# SPDX-License-Identifier: Apache-2.0
"""Loggers to store metrics and checkpoints.
In Composer, algorithms and callbacks can make calls to the :class:`~.logger.Logger`,
which then routes the calls to the appropriate :class:`~.logger_destination.LoggerDestination` instances.
... | composer-dev | composer/loggers/__init__.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.