如何在Python中使用WordNet从列表中找到类似含义的单词?

时间:2016-05-17 15:49:54

标签: python-3.x count wordnet senti-wordnet

我有一个单词列表,如'老师','教授,'讲师',我想在我的列表中找到所有这些相似的含义词,并将它们计入教师类别。我有很多这样不同的类别。如何我在python中找到类似的含义词?任何的想法 ?之前我只是用以下的词搜索:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
    UILabel *label = nil;

    //create new view if no view is available for recycling
    if (view == nil)
    {
        //don't do anything specific to the index within
        //this `if (view == nil) {...}` statement because the view will be
        //recycled and used with other index values later
        view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
        ((UIImageView *)view).image = [UIImage imageNamed:@"page.png"];
        view.contentMode = UIViewContentModeCenter;

        //back view i have just added this apart from it there is no change made by me in this method
        UIView *backView = [[UIView alloc] initWithFrame:view.bounds];
        backView.tag = 2;
        [backView setBackgroundColor:[UIColor redColor]];
        [view addSubview:backView];
        [backView setHidden:YES];
        //back view

        label = [[UILabel alloc] initWithFrame:view.bounds];
        label.backgroundColor = [UIColor clearColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [label.font fontWithSize:50];
        label.tag = 1;
        [view addSubview:label];



    }
    else
    {
        //get a reference to the label in the recycled view
        label = (UILabel *)[view viewWithTag:1];
    }

    //set item label
    //remember to always set any properties of your carousel item
    //views outside of the `if (view == nil) {...}` check otherwise
    //you'll get weird issues with carousel item content appearing
    //in the wrong place in the carousel
    label.text = [_items[index] stringValue];

    return view;
}

但问题是上面的函数只搜索函数中给出的单词,而且我不能在函数中传递所有这些单词,因为有些类别可能有5个,大约10个,大约20个,有什么方法可以找到列表中所有相似的单词..谢谢

1 个答案:

答案 0 :(得分:1)

使用循环和列表(或集)。即。

count_words(data, ["a", "b", "c"])

def count_words(data, words):
    ...
    for w in words:
       ...