2011-10-09 60 views
8

我有一个数据库包含只包含大写字母的句子。该数据库是技术性的,包含医疗术语,我想对其进行标准化,以使大写字母(接近)符合用户的期望。达到此目的的最佳方法是什么?是否有免费的数据集供我用来帮助这个过程?如何才能最好地确定单词的正确大小写?

+0

医学术语将是艰难的。 –

+1

这是特定语言,顺便说一句。你的数据是英文吗? –

+0

@Alex Yep,全英文。 – Mike

回答

4

搜寻工作在truecasing:http://en.wikipedia.org/wiki/Truecasing

这将是很容易产生,如果你有正常的市值获得类似的医疗数据自己的数据集。利用一切资源并使用映射到原始文本来训练/测试您的算法。

7

的一种方法是使用Python自然语言工具包(NLTK)来推断从POS标记大写,例如:

import nltk, re 

def truecase(text): 
    truecased_sents = [] # list of truecased sentences 
    # apply POS-tagging 
    tagged_sent = nltk.pos_tag([word.lower() for word in nltk.word_tokenize(text)]) 
    # infer capitalization from POS-tags 
    normalized_sent = [w.capitalize() if t in ["NN","NNS"] else w for (w,t) in tagged_sent] 
    # capitalize first word in sentence 
    normalized_sent[0] = normalized_sent[0].capitalize() 
    # use regular expression to get punctuation right 
    pretty_string = re.sub(" (?=[\.,'!?:;])", "", ' '.join(normalized_sent)) 
    return pretty_string 

这不会是完美的,尤其是因为我不知道你是什么数据完全看起来像,但也许你可以得到这样的想法:

>>> text = "Clonazepam Has Been Approved As An Anticonvulsant To Be Manufactured In 0.5mg, 1mg And 2mg Tablets. It Is The Generic Equivalent Of Roche Laboratories' Klonopin." 
>>> truecase(text) 
"Clonazepam has been approved as an anticonvulsant to be manufactured in 0.5mg, 1mg and 2mg Tablets. It is the generic Equivalent of Roche Laboratories' Klonopin." 
+0

伟大的解决方案。你也可能会发现这个api很有趣。 [textacy](https://pypi.python.org/pypi/textacy) – Pramit

2

最简单的方法是使用基于ngrams的拼写校正算法。

您可以使用,例如LingPipe SpellChecker。您可以找到用于预测单词空格的源代码,类似于可以预测大小写的操作。

相关问题