testwhen.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. "git.wecise.com/wecise/common/nlp/when"
  6. "git.wecise.com/wecise/common/nlp/when/rules/cn"
  7. "git.wecise.com/wecise/common/nlp/when/rules/en"
  8. "git.wecise.com/wecise/odbserver/odb/test"
  9. "gitee.com/wecisecode/util/logger"
  10. )
  11. func main() {
  12. option := &Option{Cache: CacheAll, Keyspace: "matrix", DisableInitialHostLookup: true}
  13. g, err := test.NewG(option)
  14. if err != nil {
  15. logger.Error(err.Error())
  16. } else {
  17. defer g.Close()
  18. }
  19. logger.SetConsole(true)
  20. logger.Info("iiiiiiiiiiiiiiiiiiiiii")
  21. w := when.New(nil)
  22. w.Add(en.All...)
  23. w.Add(cn.All...)
  24. logger.Info("jjjjjjjjjjjjjjjjjjjjjj")
  25. //text := "drop me a line in next wednesday at 2:25 p.m"
  26. text := "admin昨天上传的文档"
  27. r, err := w.Parse(text, time.Now())
  28. logger.Info("kkkkkkkkkkkkkkkkkkkkkk")
  29. if err != nil {
  30. logger.Info("errr ===> ", err)
  31. }
  32. if r == nil {
  33. logger.Info("r is nil !!!!!")
  34. }
  35. logger.Info("HHHHHHHHHHHHHHHHHHHHHHH", r.Context)
  36. /*fmt.Println(
  37. "the time",
  38. r.Time.String(),
  39. "mentioned in",
  40. text[r.Index:r.Index+len(r.Text)],
  41. "context",
  42. )*/
  43. if r.Context.Year != nil {
  44. fmt.Println("year ==>", *r.Context.Year)
  45. }
  46. if r.Context.Month != nil {
  47. fmt.Println("Month ==>", *r.Context.Month)
  48. }
  49. if r.Context.Day != nil {
  50. fmt.Println("Day ==>", *r.Context.Day)
  51. }
  52. if r.Context.Hour != nil {
  53. fmt.Println("Hour ==>", *r.Context.Hour)
  54. }
  55. if r.Context.Minute != nil {
  56. fmt.Println("Minute ==>", *r.Context.Minute)
  57. }
  58. if r.Context.Second != nil {
  59. fmt.Println("Second ==>", *r.Context.Second)
  60. }
  61. fmt.Println("Duration ==>", r.Context.Duration)
  62. }