基于字典的Tokenize句子

时间:2016-02-27 09:22:48

标签: python nlp

我几乎没有关键词 - RAM,扬声器,品牌,显示器等。我已经制作了这些键可以拥有的所有可能值的字典。喜欢 - RAM可以有12,12gb,12GB;显示器可以有12英寸,12英寸,12英寸。

我得到一个标题 - " Apple iPhone 5s(太空灰,16GB)"

我必须从这些标题中提取标记并映射到字典值并为每个标记指定适当的关键字。

喜欢这个 - 品牌 - 苹果,颜色 - 灰色,存储 - 16GB

我应该如何对这些句子进行标记?仅仅通过空间来做这件事就不够了 - 就像这个标题一样 - "三星大师音乐2 SM-B310E(白色)" 2将是一个令牌,可以映射到RAM,显示任何内容。

任何NLP图书馆都会对此有所帮助吗?我使用python编写代码并使用NLP。

    final_dict = {'Width': [81.28, 49.0], 'Brand': ['wd', 'lenovo', 'western digital'], 'Weight': [960.0], 'Height': [111.76, 109.22, 170.6]}
    map = {'Ram_gb' : ['gb','GB'],
           'Storage_gb' : ['gb','GB'],
           'FrontCamera' : ['MP','mp'],
           'BackCamera' : ['MP','mp'],
           'Display Resolution' : ['p','pixels'],
           'Weight' : ['gram','g','kg','Gram','KG'],
           'Generation' : ['gen','G','nd']
           }
    add_words = [""," ","-"]
    for key,value in self.final_dict.iteritems():
        if(key in map):
            adverb = map.get(key)
            new_dict = []
            for val in value:
                for ad in adverb:
                    for btw in add_words:
                        new_value = ""
                        new_value = str(val) + str(btw) + str(ad)
                        new_dict.append(new_value)
            self.final_dict[key].extend(new_dict)
            print self.final_dict[key]

这是在标题中使所有单词排列成为可能的代码。

我的标题很少 -

apple macbook pro md101hn/a 13-inch laptop (core i5/4gb/500gb/intel hd graphics), silver;
lenovo g40-45 laptop(amd e1/ 2gb ram/ 500gb hdd/ win 8.1);
lenovo g40-80 notebook(4th gen- ci3/ 4gb ram/ 500gb hdd/ win 8.1) (black);
lenovo g50-80 notebook(5th gen- ci3/ 4gb ram/ 1tb hdd/ dos) (black);
dell inspiron 3542 notebook (4th gen- ci3/ 4gb ram/ 1tb hdd/ dos), silver;

如何从这些标题中提取数据并映射到字典中的键。

喜欢标题一 -

{
'Brand' : 'apple',
'processor' : 'core',
'RAM' : '4gb',
'color' : 'silver',
'Display' : '13-inch',
'Storage' : '500gb'
}

0 个答案:

没有答案
相关问题