当前位置: 首页>>代码示例>>Python>>正文


Python EditModel.EditModel类代码示例

本文整理汇总了Python中EditModel.EditModel的典型用法代码示例。如果您正苦于以下问题:Python EditModel类的具体用法?Python EditModel怎么用?Python EditModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了EditModel类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: scan_edits

def scan_edits( edits_file ):
    
    print >> sys.stderr, "Processing "+edits_file
    editmodel = EditModel('')
    edit_probs = Counter()
    edits1 = read_edit1s(edits_file)
    print >> sys.stderr, "Counting"
    for error,correct in edits1:
        count_chars(correct)
        v, edit_types = editmodel.get_edits( correct, error )
        edit_types = set(edit_types)
        edit_types = [each for each in edit_types if each[0] != editmodel.nc]
        edit_probs.update(edit_types)
    num_char_unigrams = len(char_counts)
    print >> sys.stderr, "Normalizing"
    norm_edit_probs = {}
    for kind,str in edit_probs.keys():
        if kind == editmodel.dl:
            norm_edit_probs[(kind,str)] = (edit_probs[(kind,str)] + 1.0)/(get_char_bigram_count(str) + num_char_unigrams + 1)
        elif kind == editmodel.ins:
            norm_edit_probs[(kind,str)] = (edit_probs[(kind,str)] + 1.0)/(get_char_unigram_count(str[0]) + num_char_unigrams + 1)
        elif kind == editmodel.sub:
            #If this is a substitution, reverse the characters because of bug in get_edits
            norm_edit_probs[(kind,str[::-1])] = (edit_probs[(kind,str)] + 1.0)/(get_char_unigram_count(str[0]) + num_char_unigrams + 1)
        elif kind == editmodel.trs:
            norm_edit_probs[(kind,str)] = (edit_probs[(kind,str)] + 1.0)/(get_char_bigram_count(str) + num_char_unigrams + 1)
    print >> sys.stderr, "Writing to file - edits_model"
    serialize_data(norm_edit_probs, 'edit_model')
    serialize_data(dict(char_counts), 'char_unigram_model')
    serialize_data(dict(char_bigram_counts), 'char_bigram_model')
开发者ID:bharcode,项目名称:Programming,代码行数:30,代码来源:models.py

示例2: output

  def output(self, partId, ch_aux):
    """Uses the student code to compute the output for test cases."""
    trainCorpus = HolbrookCorpus('../data/holbrook-tagged-train.dat')

    if partId in [1,2]:
      editModel = EditModel('../data/count_1edit.txt', trainCorpus)
      return json.dumps([[(e.editedWord, e.rule()) for e in editModel.edits(line.strip())] for line in ch_aux.split("\n")])
    else:
      testCorpus = HolbrookCorpus()
      testCorpus.slurpString(ch_aux)
      lm = None
      if partId in [3,4]:
        lm = LaplaceUnigramLanguageModel(trainCorpus)
      elif partId in [5,6]:
        lm = LaplaceBigramLanguageModel(trainCorpus)
      elif partId in [7,8]:
        lm = StupidBackoffLanguageModel(trainCorpus)
      elif partId in [9,10]:
        lm = CustomLanguageModel(trainCorpus)
      else:
        print 'Unknown partId: " + partId'
        return None

      speller = SpellCorrect(lm, trainCorpus)
      output = speller.correctCorpus(testCorpus)
      # put in the part ID as well
      output = '[["%d"],%s' % (partId, output[1:])
      return output
开发者ID:cmdodge,项目名称:Autocorrect,代码行数:28,代码来源:submit.py

示例3: __init__

 def __init__(self, lm, corpus):
   """initializes the language model."""
   self.languageModel = lm
   self.editModel = EditModel('../data/count_1edit.txt', corpus)
开发者ID:gpoulter,项目名称:nlp-pa2-autocorrect,代码行数:4,代码来源:SpellCorrect.py

示例4: __init__

 def __init__(self, lm, corpus):
   self.languageModel = lm
   self.editModel = EditModel('../data/count_1edit.txt', corpus)
开发者ID:hitoshinagano,项目名称:NLP-Stanford,代码行数:3,代码来源:SpellCorrect.py

示例5: __init__

 def __init__(self, models, lm, corpus, classModel=None):
   """initializes the language model."""
   self.classModel = classModel
   self.languageModels = models
   self.languageModelFunction = lm
   self.editModel = EditModel('./data/count_1edit.txt', corpus)
开发者ID:mattetti,项目名称:misc-Python-experiments,代码行数:6,代码来源:SpellCorrect.py


注:本文中的EditModel.EditModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。