【问题标题】:function for searching web via terminal/aiml通过终端/aiml 搜索网页的功能
【发布时间】:2019-05-07 05:46:59
【问题描述】:

“我正在尝试制作一个 bash 函数,该函数将在终端上使用 aiml 模式进行网络搜索并显示结果。目前我可以从我的代码中启动不同的网站,但我无法搜索结果。例如我想说(写一个命令)“谷歌(寻找)对生活的回答和模式应该在现有的浏览器会话中创建一个新窗口并显示来自网络的生活回答的结果”有没有办法让它工作?我已经尝试过 urllib 来获取来自网络的数据,但它不起作用。谢谢 这是我的目标模式

        <pattern>OPEN GOOGLE</pattern>
        <template>
             <random>
               <li>Sure thing! </li>
               <li>Right away, ! </li>
               <li>On it! </li>
            </random>
            <system> open -a "Google Chrome" http://GOOGLE.com</system>
        </template>
    </category>


    <category>
        <pattern>GOOGLE *</pattern>
        <template>
             <random>
               <li>Sure thing! </li>
               <li>Right away,! </li>
               <li>On it! </li>
            </random>
            <system> open -a "Google Chrome" http://GOOGLE.com/search?q=<star/>"</system>
        </template>
    </category>

    <category>
        <pattern>SEARCH FOR * ON GOOGLE></pattern>
        <template>
             <srai>GOOGLE <star/></srai>
        </template>
    </category>

    <category>
        <pattern>SEARCH GOOGLE FOR *</pattern>
        <template>
             <srai>YOUTUBE <star/></srai>
        </template>
    </category>
</aiml>

【问题讨论】:

  • 我觉得使用 Google 的自定义搜索 API 与 Google 交互可能是最有意义的。那么就没有必要将命令行加入其中。点击 API 并返回 JSON,解析它并构建您的 AIML。
  • 我认为除此之外还有简单的方法,谢谢

标签: python-3.x bash search artificial-intelligence aiml


【解决方案1】:

您可以使用 标签来做到这一点。

<category>
    <pattern>SEARCH GOOGLE FOR *</pattern>
    <template>
        <link>
            <text>
                <random>
                    <li>Sure thing! </li>
                    <li>Right away, sir! </li>
                    <li>On it! </li>
                </random>
            </text>
            <url>http://GOOGLE.com/search?q=<star/></url>
        </link>
    </template>
</category>

您还可以使用 Google 的“我很幸运”功能自动打开它找到的第一个网站。

<category>
    <pattern>SEARCH GOOGLE FOR *</pattern>
    <template>
        <link>
            <text>
                <random>
                    <li>Sure thing! </li>
                    <li>Right away, sir! </li>
                    <li>On it! </li>
                </random>
            </text>
            <url>http://www.google.com/search?hl=en&amp;q=<star/>&amp;btnI=I%27m+Feeling+Lucky&amp;meta=</url>
        </link>
    </template>
</category>

【讨论】:

    猜你喜欢
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多