Skip to content

Commit

Permalink
reorganize code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bububa committed Jul 23, 2021
1 parent 0c4b443 commit 23f3c11
Show file tree
Hide file tree
Showing 12 changed files with 655 additions and 795 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![GitHub go.mod Go version of a Go module](https://img.shields.io/github/go-mod/go-version/bububa/TimeNLP.svg)](https://github.com/bububa/TimeNLP)
[![GoReportCard](https://goreportcard.com/badge/github.com/bububa/TimeNLP)](https://goreportcard.com/report/github.com/bububa/TimeNLP)
[![GitHub license](https://img.shields.io/github/license/bububa/TimeNLP.svg)](https://github.com/bububa/TimeNLP/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/bububa/TimeNLP.svg)](https://GitHub.com/bububa/TimeNLP/releases/)
[![GitHub release](https://img.shields.io/github/release/bububa/TimeNLP.svg)](https://gitHub.com/bububa/TimeNLP/releases/)

## 使用
go get -u github.com/bububa/TimeNLP
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// timenlp Time-NLP的golang版本
// Package timenlp Time-NLP的golang版本
// python 版本https://github.com/sunfiyes/Time-NLPY
// python3 版本 https://github.com/zhanzecheng/Time_NLP
// Java 版本https://github.com/shinyke/Time-NLP
Expand Down
15 changes: 15 additions & 0 deletions embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package timenlp

import (
// embed data
_ "embed"
)

//go:embed resource/regex.txt
var embedPattern string

//go:embed resource/holi_solar.json
var embedHoliSolar []byte

//go:embed resource/holi_lunar.json
var embedHoliLunar []byte
2 changes: 1 addition & 1 deletion lunar_solar_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (l *LunarSolarConverter) LunarToSolar(lunar Lunar) Solar {
return NewSolarFromInt(solar.ToInt() + offset - 1)
}

// GetBigInt
// GetBigInt lunar to int
func (l *LunarSolarConverter) GetBigInt(data int, length int, shift int) int {
return (data & (((1 << length) - 1) << shift)) >> shift
}
2 changes: 1 addition & 1 deletion parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func TestThisMondayToNextMonday(t *testing.T) {

// TestTimeSpanContext 测试时间段上下文
func TestTimeSpanContext(t *testing.T) {
normalizer := NewTimeNormalizer(false)
normalizer := NewTimeNormalizer(true)
ts := timeBase.AddDate(0, 0, int(7+4-timeBase.Weekday()))
if timeBase.Weekday() <= time.Thursday {
ts = timeBase.AddDate(0, 0, int(4-timeBase.Weekday()))
Expand Down
26 changes: 17 additions & 9 deletions range_time_enum.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package timenlp

// 范围时间的默认时间点
// RangeTimeEnum 范围时间的默认时间点
type RangeTimeEnum int

const (
DAY_BREAK RangeTimeEnum = 3 // 黎明
EARLY_MORNING RangeTimeEnum = 8 // 早
MORNING RangeTimeEnum = 10 // 上午
NOON RangeTimeEnum = 12 // 中午、午间
AFTERNOON RangeTimeEnum = 15 // 下午、午后
NIGHT RangeTimeEnum = 18 // 晚上、傍晚
LATE_NIGHT RangeTimeEnum = 20 // 晚、晚间
MID_NIGHT RangeTimeEnum = 23 // 深夜
// DAY_BREAK 黎明
DAY_BREAK RangeTimeEnum = 3
// EARLY_MORNING 早
EARLY_MORNING RangeTimeEnum = 8
// MORNING 上午
MORNING RangeTimeEnum = 10
// NOON 中午、午间
NOON RangeTimeEnum = 12
// AFTERNOON 下午、午后
AFTERNOON RangeTimeEnum = 15
// NIGHT 晚上、傍晚
NIGHT RangeTimeEnum = 18
// LATE_NIGHT 晚、晚间
LATE_NIGHT RangeTimeEnum = 20
// MID_NIGHT 深夜
MID_NIGHT RangeTimeEnum = 23
)
2 changes: 0 additions & 2 deletions resource/doc.go

This file was deleted.

14 changes: 0 additions & 14 deletions resource/embed.go

This file was deleted.

27 changes: 18 additions & 9 deletions result.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,30 @@ import "time"
type ResultType string

const (
DELTA ResultType = "delta" // 相对时间
SPAN ResultType = "span" // 时间段
TIMESTAMP ResultType = "timestamp" // 时间点
// DELTA 相对时间
DELTA ResultType = "delta"
// SPAN 时间段
SPAN ResultType = "span"
// TIMESTAMP 时间点
TIMESTAMP ResultType = "timestamp"
)

// ResultPoint 返回值包含时间点
type ResultPoint struct {
Time time.Time // 时间
Pos int `json:"pos,omitempty"` // 文字位置
Length int `json:"length,omitempty"` // 文字长度
// Time 时间
Time time.Time
// Pos 文字位置
Pos int `json:"pos,omitempty"`
// Length 文字长度
Length int `json:"length,omitempty"`
}

// Result 返回值
type Result struct {
NormalizedString string `json:"normalized_string,omitempty"` // 标准化后字符串
Type ResultType `json:"type,omitempty"` // 返回类型
Points []ResultPoint `json:"points,omitempty"` // 时间点
// NormalizedString 标准化后字符串
NormalizedString string `json:"normalized_string,omitempty"`
// Type 返回类型
Type ResultType `json:"type,omitempty"`
// Points 时间点
Points []ResultPoint `json:"points,omitempty"`
}

0 comments on commit 23f3c11

Please sign in to comment.