repo
stringlengths
2
99
file
stringlengths
13
225
code
stringlengths
0
18.3M
file_length
int64
0
18.3M
avg_line_length
float64
0
1.36M
max_line_length
int64
0
4.26M
extension_type
stringclasses
1 value
marmot
marmot-master/marmot/features/phrase/verbs_bigram_feature_extractor.py
from collections import defaultdict from marmot.features.feature_extractor import FeatureExtractor def get_verbs(language): verbs = defaultdict(str) verbs['english'] = ['VB'] verbs['spanish'] = ['VL'] return verbs[language] class VerbsBigramFeatureExtractor(FeatureExtractor): ''' Number of p...
1,412
27.836735
72
py
marmot
marmot-master/marmot/features/phrase/punctuation_bigram_feature_extractor.py
import string from marmot.features.feature_extractor import FeatureExtractor class PunctuationBigramFeatureExtractor(FeatureExtractor): ''' Number of punctuation marks in source and target: <source_number>_<target_number> ''' def __init__(self): self.punctuation = string.punctuation ...
964
27.382353
65
py
marmot
marmot-master/marmot/features/phrase/prev_word_feature_extractor.py
from __future__ import print_function import sys from marmot.features.feature_extractor import FeatureExtractor class PrevWordFeatureExtractor(FeatureExtractor): ''' Extract previous word ''' def get_feature(self, context_obj): if type(context_obj['index']) is int: first_word_idx ...
940
29.354839
106
py
marmot
marmot-master/marmot/features/phrase/alphanumeric_feature_extractor.py
from __future__ import division import sys from marmot.features.feature_extractor import FeatureExtractor class AlphaNumericFeatureExtractor(FeatureExtractor): ''' - percentage of numbers in the source - percentage of numbers in the target - absolute difference between number of numbers in the source ...
2,488
37.890625
122
py
marmot
marmot-master/marmot/features/phrase/meta_extractor.py
import sys class MetaExtractor(): ''' class which applies all feature extractors to an object ''' def __init__(self, extractors): sys.stderr.write('This is MetaExtractor init\n') self.extractors = extractors def get_features(self, context_obj): features = [] for e...
610
24.458333
59
py
marmot
marmot-master/marmot/features/phrase/token_count_feature_extractor.py
from __future__ import division from marmot.features.feature_extractor import FeatureExtractor import sys import logging import numpy as np logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO) logger = logging.getLogger('testlogger') class TokenCountFeatureExtractor(FeatureExtr...
1,747
37
92
py
marmot
marmot-master/marmot/features/phrase/lm_feature_extractor.py
from __future__ import division import sys import kenlm from marmot.features.feature_extractor import FeatureExtractor class LMFeatureExtractor(FeatureExtractor): def __init__(self, lm_file): self.model = kenlm.LanguageModel(lm_file) def get_features(self, context_obj): #sys.stderr.write("S...
723
30.478261
89
py
marmot
marmot-master/marmot/features/phrase/__init__.py
0
0
0
py
marmot
marmot-master/marmot/features/phrase/context_feature_extractor.py
import sys from marmot.features.feature_extractor import FeatureExtractor from marmot.util.ngram_window_extractor import left_context, right_context class ContextFeatureExtractor(FeatureExtractor): def get_features(self, context_obj): if 'source_token' in context_obj and len(context_obj['source_token']) ...
1,416
49.607143
147
py
marmot
marmot-master/marmot/features/phrase/phrase_alignment_feature_extractor.py
from __future__ import division, print_function import sys import numpy as np import os import errno from marmot.features.feature_extractor import FeatureExtractor from marmot.util.alignments import train_alignments, align_sentence from marmot.exceptions.no_data_error import NoDataError class PhraseAlignmentFeature...
4,109
45.179775
188
py
marmot
marmot-master/marmot/features/phrase/punctuation_feature_extractor.py
from __future__ import division import sys from marmot.features.feature_extractor import FeatureExtractor class PunctuationFeatureExtractor(FeatureExtractor): def __init__(self): self.punctuation = ['.', ',', ':', ';', '?', '!'] def get_features(self, context_obj): #sys.stderr.write("Start ...
2,189
39.555556
114
py
marmot
marmot-master/marmot/features/phrase/source_lm_feature_extractor.py
import sys import kenlm from marmot.features.feature_extractor import FeatureExtractor class SourceLMFeatureExtractor(FeatureExtractor): def __init__(self, lm_file): self.model = kenlm.LanguageModel(lm_file) def get_features(self, context_obj): #sys.stderr.write("Start SourceLMFeatureExtract...
942
36.72
100
py
marmot
marmot-master/marmot/features/phrase/next_word_feature_extractor.py
from __future__ import print_function import sys from marmot.features.feature_extractor import FeatureExtractor class PrevWordFeatureExtractor(FeatureExtractor): ''' Extract next word ''' def get_feature(self, context_obj): if type(context_obj['index']) is int: last_word_idx = con...
949
29.645161
114
py
marmot
marmot-master/marmot/features/phrase/tests/test_num_translations_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest import os from marmot.features.phrase.num_translations_feature_extractor import NumTranslationsFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class NumTranslationsFeatureExtractor...
1,474
37.815789
209
py
marmot
marmot-master/marmot/features/phrase/tests/test_punctuation_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest from marmot.features.phrase.punctuation_feature_extractor import PunctuationFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class PunctuationFeatureExtractorTests(unittest.TestCase...
3,568
42.52439
147
py
marmot
marmot-master/marmot/features/phrase/tests/test_oov_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest from marmot.features.phrase.oov_feature_extractor import OOVFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class OOVFeatureExtractorTests(unittest.TestCase): def setUp(self):...
1,044
46.5
232
py
marmot
marmot-master/marmot/features/phrase/tests/test_phrase_alignment_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest from marmot.features.phrase.phrase_alignment_feature_extractor import PhraseAlignmentFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class PhraseAlignmentFeatureExtractorTests(unit...
1,182
37.16129
136
py
marmot
marmot-master/marmot/features/phrase/tests/test_context_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest from marmot.features.phrase.context_feature_extractor import ContextFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class ContextFeatureExtractorTests(unittest.TestCase): def ...
931
36.28
232
py
marmot
marmot-master/marmot/features/phrase/tests/test_ne_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest from marmot.features.phrase.ne_feature_extractor import NEFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class AlphaNumericFeatureExtractorTests(unittest.TestCase): def setUp...
1,987
37.230769
109
py
marmot
marmot-master/marmot/features/phrase/tests/test_token_count_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest import os from marmot.features.phrase.token_count_feature_extractor import TokenCountFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class TokenCountFeatureExtractorTests(unittest....
1,945
37.92
134
py
marmot
marmot-master/marmot/features/phrase/tests/test_ngram_frequencies_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest import os from marmot.features.phrase.ngram_frequencies_feature_extractor import NgramFrequenciesFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class NgramFrequenciesFeatureExtrac...
1,245
39.193548
140
py
marmot
marmot-master/marmot/features/phrase/tests/test_alphanumeric_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest import os from marmot.features.phrase.alphanumeric_feature_extractor import AlphaNumericFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class AlphaNumericFeatureExtractorTests(unit...
2,018
38.588235
112
py
marmot
marmot-master/marmot/features/phrase/tests/test_pos_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest from marmot.features.phrase.pos_feature_extractor import POSFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class POSFeatureExtractorTests(unittest.TestCase): def setUp(self):...
2,111
36.714286
109
py
marmot
marmot-master/marmot/features/tests/test_lm_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest import os import shutil from marmot.features.lm_feature_extractor import LMFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class LMFeatureExtractorTests(unittest.TestCase): de...
3,757
60.606557
314
py
marmot
marmot-master/marmot/features/tests/test_google_translate_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest import os from marmot.features.google_translate_feature_extractor import GoogleTranslateFeatureExtractor class GoogleTranslateFeatureExtractorTests(unittest.TestCase): def setUp(self): self.gs_extractor_en = GoogleTranslateFeatureExtractor(lang='...
1,186
41.392857
210
py
marmot
marmot-master/marmot/features/tests/test_source_lm_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest import os from marmot.features.source_lm_feature_extractor import SourceLMFeatureExtractor from marmot.exceptions.no_data_error import NoDataError class LMFeatureExtractorTests(unittest.TestCase): def setUp(self): module_path = os.path.dirname(os...
3,075
61.77551
333
py
marmot
marmot-master/marmot/features/tests/test_target_token_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest from marmot.features.target_token_feature_extractor import TargetTokenFeatureExtractor class AlignmentFeatureExtractorTests(unittest.TestCase): def test_get_features(self): obj = {'token': u'hits', 'index': 2, 'target': [u'a',u'boy',u'hits',u'a',...
1,912
50.702703
273
py
marmot
marmot-master/marmot/features/tests/test_dictionary_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest import os from marmot.features.dictionary_feature_extractor import DictionaryFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class TokenCountFeatureExtractorTests(unittest.TestCase...
1,844
46.307692
179
py
marmot
marmot-master/marmot/features/tests/test_ngram_feature_extractor.py
#!/usr/bin/env python #encoding: utf-8 ''' @author: Chris Hokamp @contact: chris.hokamp@gmail.com ''' from nltk.tokenize import word_tokenize import unittest from marmot.util import ngram_window_extractor class TestNgramFeatureExtractor(unittest.TestCase): def test_extract_window(self): sen_str = 'this...
1,703
36.043478
123
py
marmot
marmot-master/marmot/features/tests/test_wordnet_feature_extractor.py
import unittest from marmot.features.wordnet_feature_extractor import WordnetFeatureExtractor class WordnetFeatureExtractorTests(unittest.TestCase): def setUp(self): self.wordnet_extractor = WordnetFeatureExtractor(src_lang='fre', tg_lang='en') # self.wordnet_extractor_fr = WordnetFeatureExtractor...
1,987
48.7
269
py
marmot
marmot-master/marmot/features/tests/test_token_count_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest import os from marmot.features.token_count_feature_extractor import TokenCountFeatureExtractor # test a class which extracts source and target token count features, and the source/target token count ratio class TokenCountFeatureExtractorTests(unittest.TestCas...
1,074
37.392857
174
py
marmot
marmot-master/marmot/features/tests/__init__.py
__author__ = 'chris'
21
10
20
py
marmot
marmot-master/marmot/features/tests/test_alignment_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import os import glob import unittest from marmot.features.alignment_feature_extractor import AlignmentFeatureExtractor class AlignmentFeatureExtractorTests(unittest.TestCase): def setUp(self): self.module_path = os.path.dirname(os.path.realpath(__file__)) ...
4,139
56.5
276
py
marmot
marmot-master/marmot/features/tests/test_pos_feature_extractor.py
#!/usr/bin/python # -*- coding: utf-8 -*- import os, sys import unittest import StringIO from marmot.features.pos_feature_extractor import POSFeatureExtractor class POSFeatureExtractorTests(unittest.TestCase): # check: POS rerpresentation in context_obj # no POS representation def setUp(self): tagge...
3,326
47.217391
263
py
marmot
marmot-master/marmot/experiment/preprocessing_utils.py
from __future__ import print_function import os import copy import multiprocessing as multi import logging import numpy as np from collections import defaultdict from sklearn.preprocessing.label import LabelBinarizer, MultiLabelBinarizer import ipdb from marmot.util.simple_corpus import SimpleCorpus from marmot.exper...
9,703
41.191304
156
py
marmot
marmot-master/marmot/experiment/extract_features_phrase.py
from __future__ import print_function, division from argparse import ArgumentParser import yaml import logging import os from marmot.experiment.import_utils import build_objects, build_object, mk_tmp_dir, call_for_each_element from marmot.experiment.preprocessing_utils import tags_from_contexts, contexts_to_features ...
7,750
46.552147
173
py
marmot
marmot-master/marmot/experiment/run_experiment_ngram_new.py
from __future__ import print_function, division from argparse import ArgumentParser import yaml import logging import os import sys import time from subprocess import call from marmot.experiment.import_utils import build_objects, build_object, call_for_each_element, import_class from marmot.experiment.preprocessing_u...
19,745
55.417143
252
py
marmot
marmot-master/marmot/experiment/crf_experiment.py
from __future__ import print_function, division from argparse import ArgumentParser import yaml import logging import copy import sys import os import time from subprocess import call from marmot.experiment.import_utils import call_for_each_element, build_object, build_objects, mk_tmp_dir from marmot.experiment.prepr...
12,883
46.895911
187
py
marmot
marmot-master/marmot/experiment/extract_features.py
from __future__ import print_function, division from argparse import ArgumentParser import yaml import logging import sys import os from marmot.experiment.import_utils import call_for_each_element, build_object, build_objects, mk_tmp_dir from marmot.experiment.preprocessing_utils import create_contexts, tags_from_con...
9,400
43.980861
167
py
marmot
marmot-master/marmot/experiment/run_experiment_pre_extracted.py
from __future__ import print_function, division from argparse import ArgumentParser import os import sys import yaml import time import logging from subprocess import call from sklearn.metrics import f1_score from marmot.experiment.import_utils import call_for_each_element, build_object, build_objects, mk_tmp_dir from...
9,518
44.328571
150
py
marmot
marmot-master/marmot/experiment/import_utils.py
from __future__ import print_function # we need numpy to check the type of objects in list_of_lists import numpy import os import sys import errno def import_class(module_name): #sys.stderr.write("Importing class %s\n" % module_name) mod_name, class_name = module_name.rsplit('.', 1) #sys.stderr.write("Got...
3,963
31.227642
147
py
marmot
marmot-master/marmot/experiment/learning_utils.py
# utils for interfacing with Scikit-Learn import logging import numpy as np import copy from multiprocessing import Pool from sklearn.metrics import f1_score from marmot.learning.pystruct_sequence_learner import PystructSequenceLearner from marmot.experiment.import_utils import call_for_each_element from marmot.experi...
9,015
44.08
203
py
marmot
marmot-master/marmot/experiment/preprocessing_utils_old.py
from __future__ import print_function import os import sys import copy import multiprocessing as multi import logging import numpy as np from collections import defaultdict from sklearn.preprocessing.label import LabelBinarizer, MultiLabelBinarizer import ipdb from marmot.util.simple_corpus import SimpleCorpus from m...
21,460
43.617464
157
py
marmot
marmot-master/marmot/experiment/converter.py
from __future__ import print_function ############################################################# # # Convert features from CRFSuite format to something else # ############################################################ import os import sys import time from argparse import ArgumentParser from sklearn.metrics import...
9,127
45.10101
178
py
marmot
marmot-master/marmot/experiment/__init__.py
0
0
0
py
marmot
marmot-master/marmot/experiment/context_utils.py
from __future__ import print_function, division import sys import numpy as np from collections import Counter ########################################################################### # # This file contains different functions for generation of non-standard # contexts (contexts where each 'token' is a list of words...
15,242
46.19195
251
py
marmot
marmot-master/marmot/experiment/svm_light_experiment.py
from __future__ import print_function, division from argparse import ArgumentParser import yaml import logging import sys import os from subprocess import call from sklearn.metrics import f1_score from marmot.experiment.import_utils import call_for_each_element, build_object, build_objects, mk_tmp_dir from marmot.exp...
19,675
45.079625
167
py
marmot
marmot-master/marmot/experiment/run_experiment_ngram.py
from __future__ import print_function, division from argparse import ArgumentParser import yaml import logging import os import sys import time from subprocess import call from marmot.experiment.import_utils import build_objects, build_object, call_for_each_element, import_class from marmot.experiment.preprocessing_u...
19,765
55.31339
252
py
marmot
marmot-master/marmot/experiment/run_experiment_word.py
from __future__ import print_function, division from argparse import ArgumentParser import yaml import logging import copy import sys from marmot.experiment.import_utils import * from marmot.experiment.preprocessing_utils import * from marmot.experiment.learning_utils import map_classifiers, predict_all from marmot.e...
15,599
48.52381
185
py
marmot
marmot-master/marmot/experiment/experiment_utils.py
from __future__ import division import numpy as np import multiprocessing as multi import logging import types import sklearn from sklearn.preprocessing import LabelBinarizer, MultiLabelBinarizer from import_utils import import_class from preprocessing_utils import map_feature_extractor logging.basicConfig(format='%(...
7,723
39.020725
212
py
marmot
marmot-master/marmot/learning/sequence_learner.py
# this is an abstract class representing a sequence learner, or 'structured' learner # implementations wrap various sequence learning tools, in order to provide a consistent interface within Marmot from abc import ABCMeta, abstractmethod class SequenceLearner(object): __metaclass__ = ABCMeta # subclasses mu...
1,016
35.321429
150
py
marmot
marmot-master/marmot/learning/pystruct_sequence_learner.py
import numpy as np from marmot.learning.sequence_learner import SequenceLearner from pystruct.models import ChainCRF from pystruct.learners import OneSlackSSVM from pystruct.learners import StructuredPerceptron # a learner which uses the pystruct library class PystructSequenceLearner(SequenceLearner): def __init_...
752
27.961538
98
py
marmot
marmot-master/marmot/learning/__init__.py
0
0
0
py
marmot
marmot-master/marmot/util/add_bigram_features.py
def add_bigram_features(features, labels): ''' Enhance feature set with features that consist of a feature + label of previous word E.g. from a set of features ['NN', 'Noun', 3] create a set ['NN_OK', 'Noun_OK', '3_OK'] ''' assert(len(features) == len(labels)) new_features = [] fo...
982
30.709677
66
py
marmot
marmot-master/marmot/util/alignments.py
import os import sys import shutil from subprocess import Popen from marmot.util.force_align import Aligner from marmot.experiment.import_utils import mk_tmp_dir def train_alignments(src_train, tg_train, tmp_dir, align_model='align_model'): cdec = os.environ['CDEC_HOME'] if cdec == '': sys.stderr.wri...
3,351
39.385542
171
py
marmot
marmot-master/marmot/util/extract_syntactic_features.py
# Extract syntactic sentence-level features from the output of Stanford parser # Parser should be run using the following command: # # for English: # java -mx3g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLP -file <INPUT> -outputFormat xml -annotators tokenize,ssplit,pos,depparse # for German: # java -mx3g -cp "*" e...
12,459
38.935897
229
py
marmot
marmot-master/marmot/util/persist_features.py
# persist features to file # feature output formats are different depending upon the datatype # if it's an ndarray, write to .csv # if it's an list of lists, write to crf++ format, with a separate file containing the feature names # if it's a dict, write to .json or pickle the object(?), write the feature names to a se...
8,421
47.682081
190
py
marmot
marmot-master/marmot/util/random_context_creator.py
import random from context_creator import ContextCreator # returns a random TARGET context for the wordset and parameters supplied to the constructor class RandomContextCreator(ContextCreator): def __init__(self, word_list, num_contexts=5000, length_bounds=[6,12], tagset=set([0])): self.word_list = set(wo...
1,529
41.5
112
py
marmot
marmot-master/marmot/util/pos_tagging.py
import os import time from subprocess import Popen def get_random_name(self, suffix=''): return 'tmp_'+suffix+str(time.time()) def get_pos_tagging(src, tagger, par_file, tmp_dir): print tmp_dir # tokenize and add the sentence end marker# # tokenization is done with nltk tmp_tokenized_name = os.p...
3,105
32.042553
102
py
marmot
marmot-master/marmot/util/context_creator.py
from abc import ABCMeta, abstractmethod # this is an abstract class which extracts contexts according to a user-provided implementation # a negative context is a context that is representative of a WRONG usage of a word # a negative context for a word may have nothing to do with a positive context (i.e. it may just be...
523
31.75
107
py
marmot
marmot-master/marmot/util/generate_crf_template.py
from __future__ import print_function import os # generates a template for crf++ feature extractor: all columns will be used as features, # no combinations of columns, no contexts (it should already be in original feature set) def generate_crf_template(feature_num, template_name='template', tmp_dir='tmp_dir'): i...
760
39.052632
90
py
marmot
marmot-master/marmot/util/__init__.py
0
0
0
py
marmot
marmot-master/marmot/util/simple_corpus.py
#!/usr/bin/env python #encoding: utf-8 from __future__ import division, print_function from gensim import utils, corpora import numpy as np import codecs from nltk.tokenize import word_tokenize, WhitespaceTokenizer from scipy import sparse import logging logging.basicConfig(format='%(asctime)s : %(levelname)s : %(me...
2,452
31.706667
91
py
marmot
marmot-master/marmot/util/ngram_window_extractor.py
#!/usr/bin/env python #encoding: utf-8 ''' @author: Chris Hokamp @contact: chris.hokamp@gmail.com ''' # this only finds the first instance of the token in the sentence (see the idx= keyword arg of the extract_window function) def locate_token(token, sentence): try: i = sentence.index(token) retur...
1,850
30.372881
123
py
marmot
marmot-master/marmot/util/corpus_context_creator.py
# a corpus_context_creator gets its contexts from a corpus of instances # the list of contexts presumably come from the parser for this particular corpus from collections import defaultdict from context_creator import ContextCreator class CorpusContextCreator(ContextCreator): """ build a corpus from a list of...
1,195
33.171429
108
py
marmot
marmot-master/marmot/util/force_align.py
#!/usr/bin/env python # # This code is partially taken from the force_align.py script of cdec project # import os import subprocess import sys import threading # Simplified, non-threadsafe version for force_align.py # Use the version in realtime for development class Aligner: def __init__(self, fwd_params, fwd_...
3,582
33.786408
148
py
marmot
marmot-master/marmot/util/call_alignment.py
from __future__ import print_function import sys from marmot.util.alignments import align_files if __name__ == "__main__": if len(sys.argv) != 4: print("Usage: python call_alignment.py src_file tg_file model") sys.exit() align_files(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[1]+'.align')
320
28.181818
76
py
marmot
marmot-master/marmot/util/tests/test_random_context_creator.py
import unittest, os from marmot.util.random_context_creator import RandomContextCreator class TestRunExperiment(unittest.TestCase): def setUp(self): module_path = os.path.dirname(__file__) self.module_path = module_path self.target_vocabulary = set(['one', 'two', 'three', 'four', 'five']) ...
743
34.428571
86
py
marmot
marmot-master/marmot/util/tests/__init__.py
__author__ = 'chris'
21
10
20
py
marmot
marmot-master/marmot/util/tests/test_context_creator.py
# TODO: stub - implement import unittest, os from marmot.util.corpus_context_creator import CorpusContextCreator class TestRunExperiment(unittest.TestCase): def setUp(self): module_path = os.path.dirname(__file__) self.module_path = module_path # create the set of tokens we're interested ...
3,323
96.764706
615
py
marmot
marmot-master/marmot/exceptions/no_data_error.py
class NoDataError(Exception): def __init__(self, field, obj, module): message = "Missing field '" + field + "' in the object " + str(obj) + " needed in " + module super(NoDataError, self).__init__(message)
227
37
100
py
marmot
marmot-master/marmot/exceptions/__init__.py
0
0
0
py
marmot
marmot-master/marmot/exceptions/no_resource_error.py
class NoResourceError(Exception): def __init__(self, resource, module): message = "No " + resource + " provided in " + str(module) super(NoResourceError, self).__init__(message)
198
38.8
66
py
marmot
marmot-master/marmot/exceptions/tests/test_features.py
import unittest import yaml import os from marmot.features.alignment_feature_extractor import AlignmentFeatureExtractor from marmot.features.pos_feature_extractor import POSFeatureExtractor from marmot.features.google_translate_feature_extractor import GoogleTranslateFeatureExtractor from marmot.features.source_lm_fea...
4,172
45.88764
313
py
marmot
marmot-master/marmot/parsers/parser.py
from abc import ABCMeta, abstractmethod # A parser takes one or more filenames and (optionally) keys # returns an object containing keys which each point to a list of lists class Parser(object): __metaclass__ = ABCMeta # subclasses must provide the implementation # the flexible args and kwargs are not id...
598
36.4375
96
py
marmot
marmot-master/marmot/parsers/whitespace_tokenized_parser.py
# parse a whitespace tokenized file, return an object with the user specified key identifying the parsed data from parser import Parser import codecs from nltk.tokenize import WhitespaceTokenizer class WhitespaceTokenizedParser(Parser): def parse(self, corpus_filename, key): assert type(corpus_filename)...
610
32.944444
109
py
marmot
marmot-master/marmot/parsers/parsers.py
#!/usr/bin/python # -*- coding: utf-8 -*- # A parser takes some input, and returns a list of contexts in the format: { 'token': <token>, index: <idx>, 'source': [<source toks>]', 'target': [<target toks>], 'tag': <tag>} # return a context object from an iterable of contexts, and a set of interesting tokens from marmo...
7,529
39.702703
178
py
marmot
marmot-master/marmot/parsers/__init__.py
0
0
0
py
marmot
marmot-master/marmot/parsers/generators_temp.py
# WORKING - move representation generators out of parsers file # TODO: these are for generating the representation from marmot.util.force_align import Aligner from marmot.util.alignments import train_alignments def mkdir_p(path): try: os.makedirs(path) except OSError as exc: # Python >2.5 if...
4,807
36.858268
132
py
marmot
marmot-master/marmot/parsers/tests/test_whitespace_tokenized_parser.py
import unittest import os import codecs from marmot.parsers.whitespace_tokenized_parser import WhitespaceTokenizedParser class TestWhitespaceTokenizedParser(unittest.TestCase): def setUp(self): module_path = os.path.dirname(__file__) self.module_path = module_path self.test_data = os.pat...
742
26.518519
80
py
marmot
marmot-master/marmot/parsers/tests/test_parsers.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest, os, tempfile, sys import glob from marmot.parsers.parsers import * from marmot.util.simple_corpus import SimpleCorpus # TODO: none of these tests adhere to the new parser API, they need to be moved, updated, or deleted class TestCorpusParser(unittest.TestCas...
3,323
39.048193
100
py
marmot
marmot-master/marmot/preprocessing/double_test_data.py
import sys, os from subprocess import check_call import argparse from collections import defaultdict from parse_xml import parse_line from get_double_corpus import get_double_corpus #naming #input WMT - <wmt> #source ||| target - <wmt>.src_trg #alignments - <wmt>.gdfa #token-aligned file - <wmt>.double #one word per ...
4,043
34.165217
226
py
marmot
marmot-master/marmot/preprocessing/preprocess_ter.py
from __future__ import print_function import sys import re import numpy as np def parse_hyp_loc_map(line): numbers = [int(x) for x in line.split()] orig2shifted = {i: j for (j, i) in list(enumerate(numbers))} shifted2orig = dict(enumerate(numbers)) return (orig2shifted, shifted2orig) def parse_sente...
7,709
36.609756
123
py
marmot
marmot-master/marmot/preprocessing/get_double_corpus.py
import sys def get_double_string( words_src, words_trg, align_str, cnt=0 ): ''' Generation of a line of double tokens. <src_list> -- list of source tokens <trg_list> -- list of target tokens <align_str> -- string with alignments in format "i-j" (source-target) Returns: list of double tokens (target_so...
2,963
28.346535
104
py
marmot
marmot-master/marmot/preprocessing/parse_xml.py
import sys from xml.dom.minidom import parseString import numpy as np from subprocess import Popen, PIPE import os class Correction: def __init__(self, _start, _end, _type, _id): self.start = _start self.end = _end self.type = _type.replace(' ','_') self.id = _id def parse_line( line ): '''parse a...
3,404
31.740385
137
py
marmot
marmot-master/marmot/preprocessing/preprocess_wmt.py
# -*- coding: utf-8 -*- import sys from xml.dom.minidom import parseString from string import punctuation import numpy as np from subprocess import Popen, PIPE, STDOUT import os, codecs from collections import defaultdict cdec_home = "" class Correction: def __init__(self, _start, _end, _type, _id): self.start...
10,588
33.947195
226
py
marmot
marmot-master/marmot/preprocessing/__init__.py
0
0
0
py
marmot
marmot-master/marmot/preprocessing/prepare_dataset.py
import argparse import sys, codecs, pickle import numpy as np import pandas as pd import preprocess_wmt import preprocess_ter # prepare a dataset for the Machine Learning component # sample call: python prepare_dataset.py -i test_data/training -v /home/chris/programs/word2vec/trunk/vectors.bin -o 'test-' def array_t...
2,823
44.548387
138
py
marmot
marmot-master/marmot/preprocessing/words_from_file.py
# get the utf8 words from a text file from nltk.tokenize import word_tokenize import codecs def get_tokens(filename): with codecs.open(filename, encoding='utf8') as input: all_lines = ' '.join(input.read().splitlines()) for word in word_tokenize(all_lines): yield word
305
22.538462
57
py
marmot
marmot-master/marmot/preprocessing/get_suffixes.py
import sys from collections import defaultdict from gensim import corpora # find the longest suffix the word contains def find_suffix( word, suffix_list, prefix=u'__' ): #start searching from the longest suffixes (length of word - 2) for i in range( min(max(suffix_list.keys()),len(word)-2), min(suffix_list.keys()...
2,509
32.918919
187
py
marmot
marmot-master/marmot/preprocessing/tests/test_preprocess_wmt.py
# -*- coding: utf-8 -*- import unittest import sys import StringIO import numpy as np from marmot.preprocessing import preprocess_wmt class TestPreprocessWMT(unittest.TestCase): def test_wrong_format(self): a_stream = StringIO.StringIO() sys.stderr = a_stream self.assertTrue(preprocess_w...
3,657
72.16
526
py
marmot
marmot-master/marmot/preprocessing/tests/test_words_from_file.py
import unittest, os from marmot.preprocessing.words_from_file import get_tokens class WordsFromFileTests(unittest.TestCase): def setUp(self): self.interesting_tokens = set(['the','it']) module_path = os.path.dirname(__file__) self.corpus_file = os.path.join(module_path, 'test_data/corpus.en...
636
30.85
80
py
marmot
marmot-master/marmot/preprocessing/tests/test_get_double_corpus.py
#!/usr/bin/python # -*- coding: utf-8 -*- import unittest import os, re from subprocess import call from marmot.preprocessing.get_double_corpus import get_double_string, get_double_corpus class GetDoubleCorpusTests(unittest.TestCase): def setUp(self): self.test_dir = os.path.dirname(os.path.realpath(__f...
2,669
46.678571
245
py
marmot
marmot-master/marmot/representations/word_qe_and_pseudo_ref_representation_generator.py
import codecs from nltk import wordpunct_tokenize from marmot.representations.representation_generator import RepresentationGenerator class WordQEAndPseudoRefRepresentationGenerator(RepresentationGenerator): ''' Generate the standard word-level format: 3 files, source, target, tags, one line per file, whites...
1,491
39.324324
115
py
marmot
marmot-master/marmot/representations/alignment_representation_generator.py
from __future__ import print_function import os import time import numpy as np from collections import defaultdict from marmot.util.alignments import train_alignments from marmot.util.force_align import Aligner from marmot.representations.representation_generator import RepresentationGenerator from marmot.experiment.i...
4,073
43.282609
127
py
marmot
marmot-master/marmot/representations/wmt_representation_generator.py
import os from nltk import word_tokenize from marmot.representations.representation_generator import RepresentationGenerator from marmot.experiment.import_utils import mk_tmp_dir class WMTRepresentationGenerator(RepresentationGenerator): def _write_to_file(self, filename, lofl): a_file = open(filename, ...
2,487
37.875
88
py
marmot
marmot-master/marmot/representations/alignment_double_representation_generator.py
from __future__ import print_function import numpy as np from collections import defaultdict from marmot.util.alignments import train_alignments from marmot.util.force_align import Aligner from marmot.representations.representation_generator import RepresentationGenerator from marmot.experiment.import_utils import mk_...
4,330
44.114583
127
py
marmot
marmot-master/marmot/representations/word_qe_representation_generator.py
import codecs from marmot.representations.representation_generator import RepresentationGenerator class WordQERepresentationGenerator(RepresentationGenerator): ''' The standard word-level format: 3 files, source, target, tags, one line per file, whitespace tokenized ''' def __init__(self, source_fil...
1,090
35.366667
106
py
marmot
marmot-master/marmot/representations/word_qe_additional_representation_generator.py
from __future__ import print_function import codecs import sys from marmot.representations.representation_generator import RepresentationGenerator class WordQEAdditionalRepresentationGenerator(RepresentationGenerator): ''' The standard word-level format + additional file(s): filename saved ''' def __...
1,503
38.578947
143
py
marmot
marmot-master/marmot/representations/segmentation_representation_generator.py
from __future__ import print_function from subprocess import call import time import re import os import codecs from marmot.util.alignments import train_alignments from marmot.util.force_align import Aligner from marmot.representations.representation_generator import RepresentationGenerator from marmot.experiment.imp...
9,490
54.829412
358
py