简体   繁体   English

Swift 中日期/时间的自然语言处理

[英]Natural Language Processing for Date/Time in Swift

Suppose when a user enters buy milk tomorrow in the text field, it should be classified as:假设当用户在 text 字段中输入buy milk today时,它应该被归类为:

  1. task: buy milk任务:买牛奶
  2. due date: tomorrow截止日期:明天
  3. tag: food标签: 食物

Is there any recommended swift library or web api that supports this?是否有任何推荐的支持这个的 swift 库或 web api?

how about trying https://github.com/quire-io/SwiftyChrono .试试https://github.com/quire-io/SwiftyChrono怎么样。 your question will be separated into three parts您的问题将分为三个部分

  1. language tagging => try to know what the object is S, V, etc.语言标记 => 尝试知道对象是 S、V 等。
  2. knowledge understanding => what buy is, what the S and O is.知识理解 => 买什么,S 和 O 是什么。
  3. ontology => milk belongs to food.本体=>牛奶属于食物。

there are huge effort to do that.要做到这一点需要付出巨大的努力。 according to my experience, the date in sentence could be parsed by detecting patterns.根据我的经验,句子中的日期可以通过检测模式来解析。 so your can trying to find NLP date parser.所以你可以尝试找到 NLP 日期解析器。

let df = DateFormatter()
df.dateStyle = .full
df.doesRelativeDateFormatting = true
dump(df.string(from: Date()))
dump(df.string(from: Date(timeIntervalSinceNow: -1*24*60*60)))

Using the date formatter you can ask it to use relative date formatting.使用日期格式化程序,您可以要求它使用相对日期格式。 This way you get localization for free as well.这样您也可以免费获得本地化。 If it can show a relative date (yesterday, today, tomorrow, etc) it will, otherwise it falls back to the dateStyle etc.如果它可以显示相对日期(昨天、今天、明天等),则它会显示,否则它会回退到 dateStyle 等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM