【问题标题】:IBM Watson Alchemy news iOS SDK SwiftIBM Watson Alchemy 新闻 iOS SDK Swift
【发布时间】:2017-06-28 21:29:56
【问题描述】:

IBM Watson iOS SDK 使用 Bluemix 上的 Alchemy News 服务返回一个字符串结果,该结果需要解析以提取 url 和已清理的标题等字段。参考:https://github.com/watson-developer-cloud/swift-sdk

我将字符串拉入一个数组并使用一些字符串方法在 swift3 中解析它,但这很普通,并且会产生不可预知的结果

是否有更优雅的方法可以访问特定字段,例如我传递给 UITableViewCell 以选择并转到 url 链接的 url 和已清理的标题。

sample code:
let alchemyDataNews = AlchemyDataNews(apiKey: apiKey)
let failure = { (error: Error) in print(error) }
let start = "now-14d" // 7 day ago
let end = "now" // today
let query = ["count": "15",
                            "dedup": "true",
                            "q.enriched.url.title": "[IBM]",
                            "return":  "enriched.url.url,enriched.url.title" "enriched.url.title,enriched.url.entities.entity.text,enriched.url.entities.entity.type"]

我还注意到搜索字符串 [IBM] 的前缀为 0,即 0[IBM],并且还看到了“A”。这些前缀是什么意思,它们记录在哪里

【问题讨论】:

    标签: swift3 ibm-cloud ibm-watson alchemyapi


    【解决方案1】:

    这是您可以从返回的负载中访问字段的一种方式。

        alchemyDataNews.getNews(from: "now-4d", to: "now", query: queryDict, failure: failWithError) { news in
    
            for doc in (news.result?.docs)! {
                var cleanedTitle = doc.source?.enriched?.url?.cleanedTitle
                var author = doc.source?.enriched?.url?.author
                var title = doc.source?.enriched?.url?.title
            }}
    

    另外,这里有一个很好的炼金术数据 API 参考链接,其中包含所有请求参数和过滤器。

    https://www.ibm.com/watson/developercloud/alchemydata-news/api/v1/

    【讨论】:

    • 谢谢 Vince,这正是我所希望的。我查看了该文档,但未能找到使用正确参数和过滤器的 Swift 语法。也许我错过了它,但现在您已经提供了这个示例,我可以轻松使用所有参数和过滤器。如果此 Swift 语法是任何地方的文档,我将不胜感激链接
    猜你喜欢
    • 1970-01-01
    • 2017-01-21
    • 2020-07-11
    • 1970-01-01
    • 2018-11-10
    • 2019-05-05
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    相关资源
    最近更新 更多