Python - 从其句子中指定语料库来执行函数?

时间:2017-06-30 02:20:35

标签: python nltk

我已经从NLTK图书馆导入了所有图书,我只想弄清楚如何定义一个语料库然后再打印一句。

例如,如果我想打印文本3的句子1,则打印文本4的句子2

import nltk
from nltk.book import *
print(???)
print(???)

我已经尝试了以下组合,这些组合不起作用:

print(text3.sent1)
print(text4.sent2)

print(sent1.text3)
print(sent2.text4)

print(text3(sent1))
print(text4(sent2))

我是python的新手,所以它可能是一个基本问题,但我似乎无法在其他地方找到解决方案。

非常感谢,提前!

2 个答案:

答案 0 :(得分:0)

简单的例子可以是:

<Button x:Name="BlowMoldingButton" Tag="2204"  Height="60" Width="60" >
    <Button.Triggers>
        <EventTrigger RoutedEvent="Button.Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Duration="0:0:3" RepeatBehavior="Forever" Storyboard.TargetName="BlowMoldingButton" Storyboard.TargetProperty="Background">
                        <DiscreteObjectKeyFrame KeyTime="0:0:0" >
                            <DiscreteObjectKeyFrame.Value>
                                <ImageBrush ImageSource="Assets/MapImages/innerRing.png" />
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                        <DiscreteObjectKeyFrame KeyTime="0:0:1" >
                            <DiscreteObjectKeyFrame.Value>
                                <ImageBrush ImageSource="Assets/MapImages/middleRing.png" />
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                        <DiscreteObjectKeyFrame KeyTime="0:0:2" >
                            <DiscreteObjectKeyFrame.Value>
                                <ImageBrush ImageSource="Assets/MapImages/outerRing.png" />
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Button.Triggers>
</Button>

希望这有帮助。

答案 1 :(得分:-1)

您需要先将文本拆分为句子列表。

如果您已经有text3text4

from nltk.tokenize import sent_tokenize

sents = sent_tokenize(text3)
print(sents[0])  # the first sentence in the list is at position 0

sents = sent_tokenize(text4)
print(sents[1])  # the second sentence in the list is at position 1

print(text3[0])  # prints the first word of text3

您似乎需要NLTK教程和python教程。幸运的是,the NLTK book都是。