예제 #1
0
    def check_compatibility(self, word, prefix, stem, suffix):
        """Returns all possible compatible solutions of a prefix, stem and suffix"""
        solutions = []

        # loop through possible prefix entries
        for prefix_entry in self.prefixes[prefix]:
            # loop through possible stem entries
            for stem_entry in self.stems[stem]:
                # check if prefix and stem are compatible
                if not self.are_prefix_stem_compatible(prefix_entry,
                                                       stem_entry):
                    continue
                # valid prefix and stem combo, so continue
                # loop through possible suffix entries
                for suffix_entry in self.suffixes[suffix]:
                    if not self.are_stem_suffix_compatible(
                            stem_entry, suffix_entry):
                        continue
                    if not self.are_stem_suffix_compatible(
                            stem_entry, suffix_entry):
                        continue

                    # if we reached this point, the prefix-stem-suffix are compatible
                    # return all the information necessary to display
                    # what do we want?
                    # 1. Arabic form (the original word)
                    # 2. transliterated fully-vowelled form (TODO: split into pieces?)
                    # 3. root of the stem (TODO)
                    # 4. part of speech (just of the stem, or all?)
                    # 5. gloss

                    vowelled_form = prefix_entry.vowelled + \
                                    stem_entry.vowelled + \
                                    suffix_entry.vowelled

                    gloss = "%s + %s + %s" % (prefix_entry.gloss,
                                              stem_entry.gloss,
                                              suffix_entry.gloss)
                    gloss = gloss.strip().strip("+").strip()

                    solutions.append({
                        'word':
                        transliterate.b2u(word),
                        'vowelled':
                        transliterate.b2u(vowelled_form),
                        'transliteration':
                        transliterate.b2ala(vowelled_form),
                        'root':
                        transliterate.b2u(stem_entry.root),
                        'pos':
                        stem_entry.pos,
                        'gloss':
                        gloss
                    })

        return solutions
예제 #2
0
 def information(self, words):
     """Return unglossed information for a list of Arabic words (used when analyse() turned up empty)"""
     solutions = list()
     for word in words:
         solutions.append({'word': word,
                           'vowelled': "",
                           'transliteration': transliterate.b2ala(transliterate.u2b(word)),
                           'pos': "",
                           'root': "",
                           'gloss': "Not found in dictionary"})
     return solutions
예제 #3
0
    def check_compatibility(self, word, prefix, stem, suffix):
        """Returns all possible compatible solutions of a prefix, stem and suffix"""
        solutions = []
        
        # loop through possible prefix entries
        for prefix_entry in self.prefixes[prefix]:        
            # loop through possible stem entries
            for stem_entry in self.stems[stem]:
                # check if prefix and stem are compatible
                if not self.are_prefix_stem_compatible(prefix_entry, stem_entry):
                    continue
                # valid prefix and stem combo, so continue
                # loop through possible suffix entries
                for suffix_entry in self.suffixes[suffix]:
                    if not self.are_stem_suffix_compatible(stem_entry, suffix_entry):
                        continue
                    if not self.are_stem_suffix_compatible(stem_entry, suffix_entry):
                        continue

                    # if we reached this point, the prefix-stem-suffix are compatible
                    # return all the information necessary to display
                    # what do we want?
                    # 1. Arabic form (the original word)
                    # 2. transliterated fully-vowelled form (TODO: split into pieces?)
                    # 3. root of the stem (TODO)
                    # 4. part of speech (just of the stem, or all?)
                    # 5. gloss

                    vowelled_form = prefix_entry.vowelled + \
                                    stem_entry.vowelled + \
                                    suffix_entry.vowelled

                    gloss = "%s + %s + %s" % (prefix_entry.gloss, stem_entry.gloss, suffix_entry.gloss)
                    gloss = gloss.strip().strip("+").strip()

                    solutions.append({'word': transliterate.b2u(word), 
                                      'vowelled': transliterate.b2u(vowelled_form),
                                      'transliteration': transliterate.b2ala(vowelled_form), 
                                      'root': transliterate.b2u(stem_entry.root),
                                      'pos': stem_entry.pos, 
                                      'gloss': gloss})
                
        return solutions
예제 #4
0
 def information(self, words):
     """Return unglossed information for a list of Arabic words (used when analyse() turned up empty)"""
     solutions = list()
     for word in words:
         solutions.append({
             'word':
             word,
             'vowelled':
             "",
             'transliteration':
             transliterate.b2ala(transliterate.u2b(word)),
             'pos':
             "",
             'root':
             "",
             'gloss':
             "Not found in dictionary"
         })
     return solutions