コード例 #1
0
def customize_matrix(path, arch_type, destination=None):
    if os.path.isdir(path):
        path = os.path.join(path, 'choices')
    # if no destination dir is specified, just use the choices file's dir
    destination = destination or os.path.dirname(path)

    global ch
    ch = ChoicesFile(path)

    language = ch['language']

    grammar_path = get_grammar_path(
        ch.get('iso-code', language).lower(), language.lower(), destination)

    # delete any existing contents at grammar path
    if os.path.exists(grammar_path):
        shutil.rmtree(grammar_path)
    # the rsync command won't create the target dirs, so do it now
    os.makedirs(grammar_path)

    # Use the following command when python2.6 is available
    #shutil.copytree('matrix-core', grammar_path,
    #                ignore=shutil.ignore_patterns('.svn'))
    IGNORE = open(os.devnull, 'w')
    try:
        call([
            'rsync', '-a', '--exclude=.svn',
            get_matrix_core_path() + os.path.sep, grammar_path
        ],
             stdout=IGNORE,
             stderr=IGNORE)
    except OSError, er:
        print "OS Error. Most likely rsync is not installed."
        print er.message
        sys.exit(1)
コード例 #2
0
  def test_word_order_determiners_no_determiner_answer(self):
    c = ChoicesFile()

    # order but no determiners
    c = ChoicesFile()
    c['noun-det-order'] = 'noun-det'
    self.assertError(c, 'has-dets')
コード例 #3
0
    def test_features(self):
        choices = ChoicesFile("web/sample-choices/mini-english")
        actual = choices.features()

        expected = [['number', 'sg|sg;pl|pl', 'LOCAL.CONT.HOOK.INDEX.PNG.NUM', 'noun', 'y'],
                    ['person', '1st|1st;2nd|2nd;3rd|3rd', 'LOCAL.CONT.HOOK.INDEX.PNG.PER', 'noun', 'y'],
                    ['argument structure', 'intrans|intransitive;trans|transitive', '', 'verb', 'n'],
                    ['negation', 'plus|plus;minus|minus', '', 'verb', 'y'],
                    ['information-structure meaning', 'focus|focus;topic|topic;contrast|contrast;semantic-focus|non-contrastive-focus;contrast-focus|contrastive-focus;aboutness-topic|non-contrastive-topic;contrast-topic|contrastive-topic;focus-or-topic|focus-or-topic;contrast-or-focus|contrast-or-focus;contrast-or-topic|contrast-or-topic;non-topic|non-topic;non-focus|non-focus;bg|background', 'LOCAL.CONT.HOOK.ICONS-KEY', 'both', 'n']]

        self.assertEqual(actual, expected)
コード例 #4
0
 def test_set(self):
     c = ChoicesFile() # no file loaded
     self.assertEqual(c.choices, {})
     c['abc'] = 5
     self.assertEqual(c.choices, {'abc':5})
     c['def2_ghi'] = 2
     self.assertEqual(c.choices, {'abc':5, 'def':[None, {'ghi':2}]})
     c['def1_ghi'] = 1
     self.assertEqual(c.choices, {'abc':5, 'def':[{'ghi':1}, {'ghi':2}]})
     c = ChoicesFile() # no file loaded
     c['rst_uvw'] = 2
     self.assertEqual(c.choices, {'rst_uvw': 2})
コード例 #5
0
    def test_other_features(self):
        # a feature without a name, a type, or a name for its value
        c = ChoicesFile()
        c['feature1_value1_supertype1_name'] = 'dummy'
        self.assertErrors(
            c, ['feature1_name', 'feature1_type', 'feature1_value1_name'])

        # a feature without a name, a type, or a supertype for its value
        c = ChoicesFile()
        c['feature1_value1_name'] = 'dummy'
        self.assertErrors(c, [
            'feature1_name', 'feature1_type', 'feature1_value1_supertype1_name'
        ])
コード例 #6
0
  def test_word_order_osv_vp_before_illegal(self):
    c = ChoicesFile()

    c['word-order'] = 'osv'
    c['aux-comp'] = 'vp'
    c['aux-comp-order'] = 'before'
    self.assertError(c, 'aux-comp')
コード例 #7
0
  def test_word_order_determiners_no_determiners_with_determiner_lex(self):
    c = ChoicesFile()

    # determiners=no but determiner in the lexicon
    c['has-dets'] = 'no'
    c['det1_name'] = 'dummy'
    self.assertError(c, 'has-dets')
コード例 #8
0
ファイル: choices_test.py プロジェクト: delph-in/matrix
 def test_del(self):
     c = ChoicesFile()  # no file loaded
     c['abc'] = 5
     self.assertEqual(c.choices, {'abc': 5})
     del c['abc']
     self.assertEqual(c.choices, {})
     c['abc1_def'] = 1
     c['abc2_def'] = 2
     c['abc2_ghi'] = 3
     self.assertEqual(c.choices,
                      {'abc': [{
                          'def': 1
                      }, {
                          'def': 2,
                          'ghi': 3
                      }]})
     del c['abc2_def']
     self.assertEqual(c.choices, {'abc': [{'def': 1}, {'ghi': 3}]})
     del c['abc2']
     self.assertEqual(c.choices, {'abc': [{'def': 1}, None]})
     c['abc2_def'] = 2
     c['abc3_def'] = 3
     self.assertEqual(c.choices,
                      {'abc': [{
                          'def': 1
                      }, {
                          'def': 2
                      }, {
                          'def': 3
                      }]})
     del c['abc2']
     self.assertEqual(c.choices, {'abc': [{'def': 1}, None, {'def': 3}]})
     del c['abc']
     self.assertEqual(c.choices, {})
コード例 #9
0
  def test_lexicon_requires_one_noun_two_verbs(self):
    c = ChoicesFile()

    # not enough nouns and verbs
    self.assertWarnings(c, ('noun1_stem1_orth',
                            'verb1_valence',
                            'verb2_valence'))
コード例 #10
0
 def test_coordination_missing_affix_answers(self):
   # marked by affixes on NP, VP, or S (not supported yet)
   for phrase in ('np', 'vp', 's'):
     c = ChoicesFile()
     c['cs1_mark'] = 'affix'
     c['cs1_' + phrase] = 'on'
     self.assertError(c, 'cs1_mark')
コード例 #11
0
  def test_person_no_first_person_answer(self):
    c = ChoicesFile()

    # no answer for first-person in a language with a first person
    for person in ('1-2-3', '1-2-3-4', '1-non-1'):
      c['person'] = person
      self.assertError(c, 'first-person')
コード例 #12
0
  def test_case_additional_cases_require_other_cases(self):
    c = ChoicesFile()

    # if there's no case, additional cases can't be specified
    c['case-marking'] = 'none'
    c['case1_name'] = 'test'
    self.assertError(c, 'case1_name')
コード例 #13
0
  def test_lexicon_obligatory_determiners_require_determiners(self):
    c = ChoicesFile()

    # determiners obligatory, but not determiners
    c['noun1_det'] = 'obl'
    c['has-dets'] = 'no'
    self.assertErrors(c, ('has-dets', 'noun1_det'))
コード例 #14
0
  def test_general_language_required(self):
    c = ChoicesFile()

    # no language
    vr = validate(c)
    self.assertError(c, 'language')
    self.assertWarning(c, 'archive')
コード例 #15
0
  def test_word_order_vso_vp_after_illegal(self):
    c = ChoicesFile()

    c['word-order'] = 'vso'
    c['aux-comp'] = 'vp'
    c['aux-comp-order'] = 'after'
    self.assertError(c, 'aux-comp')
コード例 #16
0
  def test_sentential_negation_adverb_requires_other_answers(self):
    c = ChoicesFile()

    # auxiliary selects neg complement,
    # but no auxiliaries ('has-aux' != 'yes')
    c['comp-neg'] = 'on'
    c['comp-neg-head'] = 'aux'
    self.assertError(c, 'comp-neg-head')
コード例 #17
0
  def test_sentential_negation_adverb_requires_other_answers(self):
    c = ChoicesFile()

    # negation via adverb and simple negation
    # but no answers for other questions
    c['adv-neg'] = 'on'
    c['neg-exp'] = '1'
    self.assertErrors(c, ('neg-mod', 'neg-order', 'neg-adv-orth'))
コード例 #18
0
  def test_person_first_person_answer_without_person(self):
    c = ChoicesFile()

    # an answer for first-person in a language with no first person
    c['first-person'] = 'incl-excl'
    for person in ('none', '2-non-2', '3-non-3'):
      c['person'] = person
      self.assertError(c, 'first-person')
コード例 #19
0
  def test_person_first_person_answer(self):
    c = ChoicesFile()

    # answer for first-person in a language with a first person
    c['first-person'] = 'incl-excl'
    for person in ('1-2-3', '1-2-3-4', '1-non-1'):
      c['person'] = person
      self.assertNoError(c, 'first-person')
コード例 #20
0
  def test_case_answer(self):
    c = ChoicesFile()

    # no answer for case
    c['case-marking'] = 'nom-acc'
    c['case-marking-nom-case-name'] = 'nom'
    c['case-marking-acc-case-name'] = 'acc'
    self.assertNoError(c, 'case-marking')
コード例 #21
0
 def test_coordination_no_asyndeton_answers(self):
   c = ChoicesFile()
   # asyndeton but with mark, order, and orth specified
   c['cs1_pat'] = 'a'
   c['cs1_mark'] = 'dummy'
   c['cs1_order'] = 'dummy'
   c['cs1_orth'] = 'dummy'
   self.assertErrors(c, ('cs1_mark', 'cs1_order', 'cs1_orth'))
コード例 #22
0
 def test_argopt(self):
   c = ChoicesFile()
   c['subj-drop'] = 'on'
   c['obj-drop'] = 'on'
   c['context1_feat1_dummy'] = 'dummy'
   self.assertErrors(c, ('subj-mark-drop', 'subj-mark-no-drop',
                         'obj-mark-drop', 'obj-mark-no-drop',
                         'context1_feat1_head'))
コード例 #23
0
 def test_full_key(self):
     c = ChoicesFile()
     self.assertEqual(c.choices.full_key, None)
     c['abc1_def'] = 1
     c['abc2_def'] = 2
     self.assertEqual(c['abc'].full_key, 'abc')
     for i, key in enumerate(c['abc']):
         self.assertEqual(key.full_key, 'abc' + str(i+1))
コード例 #24
0
  def test_lexicon_verb_requires_valence_orth_pred(self):
    c = ChoicesFile()

    c['verb1_dummy'] = 'dummy'
    c['verb1_stem1_dummy'] = 'dummy'
    self.assertErrors(c, ('verb1_valence',
                          'verb1_stem1_orth',
                          'verb1_stem1_pred'))
コード例 #25
0
 def test_tense_legal_supertype(self):
   # subtypes defined for incorrect supertype
   for st in self.tenses:
     for t in (x for x in self.tenses if x != st):
       c = ChoicesFile()
       c[st] = 'on'
       c[t + '-subtype1_name'] = 'dummy'
       self.assertError(c, t + '-subtype1_name')
コード例 #26
0
    def test_names(self):
        # Pairs of [variable prefix, value suffix].  Appending 'name' to the
        # prefix gives the variable name (e.g., 'case1_name').  The suffix
        # tells what the system will append to the end of the *value* of
        # that variable.
        variables = [['nom-acc-nom-case-', ''],
                     ['case1_', ''], ['number1_', ''], ['gender1_', ''],
                     ['feature1_', ''], ['feature1_value1_', ''],
                     ['tense1_', ''], ['aspect1_', ''], ['situation1_', ''],
                     ['form-subtype1_', ''], ['noun1_', '-noun-lex'],
                     ['noun2_', '-noun-lex'], ['det1_', '-determiner-lex'],
                     ['det2_', '-determiner-lex'], ['verb1_', '-verb-lex'],
                     ['verb2_', '-verb-lex'], ['noun-pc1_', '-lex-rule'],
                     ['noun-pc1_lrt1_',
                      '-lex-rule'], ['noun-pc2_', '-lex-rule'],
                     ['noun-pc2_lrt1_', '-lex-rule']]

        # Name for causing collisions, made up of the lower-case letter 'a' in:
        #   Latin, accented Latin, accented Latin, Greek, Cyrillic, Armenian
        value = 'aáāαаա'

        for v1 in variables:
            # first try colliding with an existing name (head-comp-phrase)
            if not v1[1]:  # won't collide if there's a suffix
                name = v1[0] + 'name'
                c = ChoicesFile()
                c[name] = 'head-comp-phrase'
                self.assertError(c, name)

            # next try colliding pairs of names
            for v2 in [x for x in variables if x[0] != v1[0]]:
                if v1[1] == v2[1]:  # won't collide with different suffixes
                    name1 = v1[0] + 'name'
                    name2 = v2[0] + 'name'

                    c = ChoicesFile()

                    # same case
                    c[name1] = value
                    c[name2] = value

                    # different case (should still collide)
                    c[name1] = value.lower()
                    c[name2] = value.upper()
                    self.assertErrors(c, [name1, name2])
コード例 #27
0
  def test_general_illegal_language_characters_anywhere(self):
    c = ChoicesFile()

    for bad_ch in chr(20) + '?*:<>|/\\"^':
      c['language'] = bad_ch + 'x'
      self.assertError(c, 'language')

      c['language'] = 'x' + bad_ch + 'x'
      self.assertError(c, 'language')
コード例 #28
0
  def test_lexicon_noun_requires_determiners_orth_pred(self):
    c = ChoicesFile()

    # noun with no answer about determiners, and a stem with no orth or pred
    c['noun1_dummy'] = 'dummy'
    c['noun1_stem1_dummy'] = 'dummy'
    self.assertErrors(c, ('noun1_det',
                          'noun1_stem1_orth',
                          'noun1_stem1_pred'))
コード例 #29
0
 def test_other_features_requires_name_type_value(self):
   # a feature with a name, a type, and a name for its value
   c = ChoicesFile()
   c['feature1_name'] = 'dummy_name'
   c['feature1_type'] = 'dummy_type'
   c['feature1_value1_name'] = 'dummy_value_name'
   c['feature1_value1_supertype1_name'] = 'dummy_name'
   self.assertNoErrors(c, ('feature1_name', 'feature1_type',
                           'feature1_value1_name', 'feature1_value1_supertype1_name'))
コード例 #30
0
 def test_lexicon_features_illegal_name_value(self):
   # try a bad feature and value everywhere
   for p in ('scale',
             'noun', 'verb', 'adj', 'det', 'aux', #'cop', # TODO: why doesn't copula trigger this?
             #'noun-pc1_lrt', 'verb-pc1_lrt', 'det-pc1_lrt', # TODO: Move this to morphotactics?
             'context'):
     c = ChoicesFile()
     c[p + '1_feat1_name'] = 'dummy'
     c[p + '1_feat1_value'] = 'dummy'
     self.assertErrors(c, (p + '1_feat1_name', p + '1_feat1_value'))