Express Alexa技能发展

Express Alexa技能发展,express,raspberry-pi,alexa,alexa-skills-kit,alexa-voice-service,Express,Raspberry Pi,Alexa,Alexa Skills Kit,Alexa Voice Service,我正在寻找一种方法,使用Alexa作为一个通知和字典系统,用于从网站发布新的论文和公告 为此,我将使用Raspberry上的Node.js实例来抓取新的PDF文件 我对Alexa环境很陌生,正在寻找一些方向 问:有没有一种方法可以让Alexa查找这些PDF,并阅读诸如维基百科查询技巧之类的关键词的定义? 问:让树莓在互联网上不公开,而是在中间将数据推送到alexa查询的云数据库,这样会更好吗? 问:我必须以机器可读的格式解析它吗? 问:有没有更好的方法来抓取数据 感谢您提供的任何建议我相信您是在

我正在寻找一种方法,使用Alexa作为一个通知和字典系统,用于从网站发布新的论文和公告

为此,我将使用Raspberry上的Node.js实例来抓取新的PDF文件

我对Alexa环境很陌生,正在寻找一些方向

问:有没有一种方法可以让Alexa查找这些PDF,并阅读诸如维基百科查询技巧之类的关键词的定义? 问:让树莓在互联网上不公开,而是在中间将数据推送到alexa查询的云数据库,这样会更好吗? 问:我必须以机器可读的格式解析它吗? 问:有没有更好的方法来抓取数据


感谢您提供的任何建议

我相信您是在问如何制作Alexa技能,可以提出诸如“是否有新论文?”

正确的说法是,好的设计是将刮板分离并发布到数据库。然后,您可以创建一个技能,使用带有AMAZON.SearchQuery槽的意图来捕获用户查询。您的技能代码可以执行数据库查找并决定如何响应


您可能会发现以下内容很有用:。

Q1。是的,有一种方法可以让Alexa查找这些PDF并阅读定义。Amazon Alexa支持lambda函数。Lambda支持.Net内核。Foxit PDF SDK 6.4在.Net内核中工作。Foxit PDF SDK 6.4支持在PDF中搜索关键字。您可以使用Foxxit PDF SDK搜索关键字,并尝试解析PDF中的文本数据以获取定义

此解决方案需要用于.net的Foxit PDF SDK 6.4。您可以通过以下链接找到评估包的请求:

要开始添加fsdk_dotnet.dll作为对Visual Studio“AWS Lambda项目(.Net Core-C#)的引用,fsdk_dotnet.dll位于评估包的lib目录中。完成后,可以使用语句添加以下内容

using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
对于您的函数,它将如下所示

public string SearchPDF(string inputPDF, string searchTerm)//inputPDF is the PDF path with the PDF itself and its .pdf extension.  the serachTerm is the term you want to search.
{
    string sn = "SNValue"; //the SN value provided in the evaluation package at lib\gsdk_sn.txt
    string key = "SignKeyValue"; //the Sign value provided in evaluation package at lib\gsdk_key.txt
    ErrorCode error_code;
    try
    {
        error_code = Library.Initialize(sn, key);  //Unlocks the library to be used.  Make sure you update the sn and key file accordingly.
        if (error_code != ErrorCode.e_ErrSuccess)
        {
            return error_code.ToString();
        }
        PDFDoc doc = new PDFDoc(inputPDF); 
        error_code = doc.Load(null); //Loads the PDF into the Foxit PDF SDK
        if (error_code != ErrorCode.e_ErrSuccess)
        {
            return error_code.ToString(); //Returns a error code if loading the document fails
        }

        using (TextSearch search = new TextSearch(doc, null))
        {
            int start_index = 0;
            int end_index = doc.GetPageCount() - 1;
            search.SetStartPage(0);
            search.SetEndPage(doc.GetPageCount() - 1);
            search.SetPattern(searchTerm); //Sets the search term to be search in the PDF

            Int32 flags = (int)TextSearch.SearchFlags.e_SearchNormal;
            // if want to specify flags, you can do as followings:
            // flags |= TextSearch::e_SearchMatchCase;
            // flags |= TextSearch::e_SearchMatchWholeWord;
            // flags |= TextSearch::e_SearchConsecutive;

            int match_count = 0;
            while (search.FindNext())
            {
                RectFArray rect_array = search.GetMatchRects()
                string sentenceWithSearchTerm = search.GetMatchSentence();// Gets the sentence with the search term
                match_count++;
            }
        }

        doc.Dispose();
        Library.Release();
    }
    catch (foxit.PDFException e)
    {
        return e.Message;
    }
    catch (Exception e)
    {
        return e.Message;
    }
    return error_code.ToString().ToUpper(); //If successful this will return the "E_ERRSUCCESS." Please check out the headers for other error codes.
}
问题2:上述解决方案使用AWS Lambda,这将需要互联网。但是,如果希望将PDF页面中的文本提取到数据库,则不使用数据库。上面的代码显示了如何使用字符串数据获取句子。如果您想获得PDF格式的所有文本,请参阅下面的代码

 using (var doc = new PDFDoc(inputPDF)){
    error_code = doc.Load(null);
    if (error_code != ErrorCode.e_ErrSuccess)
    {
        return error_code.ToString();
    }

    // Get page count
    int pageCount = doc.GetPageCount();
    for (int i = 0; i < pageCount; i++) //A loop that goes through each page
    {
        using (var page = doc.GetPage(i))
        {
            // Parse page
            page.StartParse((int)PDFPage.ParseFlags.e_ParsePageNormal, null, false);
            // Get the text select object.
            using (var text_select = new TextPage(page, (int)TextPage.TextParseFlags.e_ParseTextNormal))
            {
                int count = text_select.GetCharCount();
                if (count > 0)
                {
                    String chars = text_select.GetChars(0, count); //gets the text on the PDF page.
                }
            }
        }
    }   
}
使用(var doc=new PDFDoc(inputPDF)){
错误代码=单据加载(空);
if(error\u code!=ErrorCode.e\u ErrSuccess)
{
返回错误_code.ToString();
}
//获取页面计数
int pageCount=doc.GetPageCount();
for(int i=0;i0)
{
String chars=text_select.GetChars(0,count);//获取PDF页面上的文本。
}
}
}
}   
}
第三季度。我不确定你所说的机器可读格式是什么意思,但Foxit PDF SDK可以提供字符串格式的文本

第四季度。抓取PDF文本数据的最佳方法是使用我上面提供的解决方案。

请披露任何内容,不要将该网站用作通过发布来推广您的网站的方式。看见