Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix week&date format #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
250 changes: 127 additions & 123 deletions src/com/time/nlp/TimeUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -634,29 +634,6 @@ public void norm_setCurRelated() {
calendar.add(Calendar.MONTH, 1);
}

rule = "大前天";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
calendar.add(Calendar.DATE, -3);
}

rule = "(?<!大)前天";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
calendar.add(Calendar.DATE, -2);
}

rule = "昨";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
calendar.add(Calendar.DATE, -1);
}

rule = "今(?!年)";
pattern = Pattern.compile(rule);
Expand All @@ -674,119 +651,146 @@ public void norm_setCurRelated() {
calendar.add(Calendar.DATE, 1);
}

rule = "(?<!大)后天";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
calendar.add(Calendar.DATE, 2);
}
if(_tp.tunit[2]==-1){
rule = "大前天";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
calendar.add(Calendar.DATE, -3);
}

rule = "大后天";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
calendar.add(Calendar.DATE, 3);
}
rule = "(?<!大)前天";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
calendar.add(Calendar.DATE, -2);
}

rule = "(?<=(上上(周|星期)))[1-7]?";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
int week;
try {
week = Integer.parseInt(match.group());
} catch (NumberFormatException e) {
week = 1;
rule = "(?<!大)后天";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
calendar.add(Calendar.DATE, 2);
}
if (week == 7)
week = 1;
else
week++;
calendar.add(Calendar.WEEK_OF_MONTH, -2);
calendar.set(Calendar.DAY_OF_WEEK, week);
}

rule = "(?<=((?<!上)上(周|星期)))[1-7]?";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
int week;
try {
week = Integer.parseInt(match.group());
} catch (NumberFormatException e) {
week = 1;
rule = "大后天";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
calendar.add(Calendar.DATE, 3);
}
if (week == 7)
week = 1;
else
week++;
calendar.add(Calendar.WEEK_OF_MONTH, -1);
calendar.set(Calendar.DAY_OF_WEEK, week);
}

rule = "(?<=((?<!下)下(周|星期)))[1-7]?";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
int week;
try {
week = Integer.parseInt(match.group());
} catch (NumberFormatException e) {
week = 1;
rule = "昨";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
calendar.add(Calendar.DATE, -1);
}
if (week == 7)
week = 1;
else
week++;
calendar.add(Calendar.WEEK_OF_MONTH, 1);
calendar.set(Calendar.DAY_OF_WEEK, week);
}

rule = "(?<=(下下(周|星期)))[1-7]?";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
int week;
try {
week = Integer.parseInt(match.group());
} catch (NumberFormatException e) {
week = 1;
rule = "(?<=(上上(周|星期)))[1-7]?";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
int week;
try {
week = Integer.parseInt(match.group());
} catch (NumberFormatException e) {
week = 1;
}
if (week == 7)
week = 1;
else
week++;
calendar.add(Calendar.WEEK_OF_MONTH, -2);
calendar.set(Calendar.DAY_OF_WEEK, week);
}
if (week == 7)
week = 1;
else
week++;
calendar.add(Calendar.WEEK_OF_MONTH, 2);
calendar.set(Calendar.DAY_OF_WEEK, week);
}

rule = "(?<=((?<!(上|下))(周|星期)))[1-7]?";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
int week;
try {
week = Integer.parseInt(match.group());
} catch (NumberFormatException e) {
week = 1;
rule = "(?<=((?<!上)上(周|星期)))[1-7]?";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
int week;
try {
week = Integer.parseInt(match.group());
} catch (NumberFormatException e) {
week = 1;
}
if (week == 7)
week = 1;
else
week++;
calendar.add(Calendar.WEEK_OF_MONTH, -1);
calendar.set(Calendar.DAY_OF_WEEK, week);
}

rule = "(?<=((?<!下)下(周|星期)))[1-7]?";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
int week;
try {
week = Integer.parseInt(match.group());
} catch (NumberFormatException e) {
week = 1;
}
if (week == 7)
week = 1;
else
week++;
calendar.add(Calendar.WEEK_OF_MONTH, 1);
calendar.set(Calendar.DAY_OF_WEEK, week);
}

rule = "(?<=(下下(周|星期)))[1-7]?";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
int week;
try {
week = Integer.parseInt(match.group());
} catch (NumberFormatException e) {
week = 1;
}
if (week == 7)
week = 1;
else
week++;
calendar.add(Calendar.WEEK_OF_MONTH, 2);
calendar.set(Calendar.DAY_OF_WEEK, week);
}

rule = "(?<=((?<!(上|下))(周|星期)))[1-7]?";
pattern = Pattern.compile(rule);
match = pattern.matcher(Time_Expression);
if (match.find()) {
flag[2] = true;
int week;
try {
week = Integer.parseInt(match.group());
} catch (NumberFormatException e) {
week = 1;
}
if (week == 7)
week = 1;
else
week++;
calendar.add(Calendar.WEEK_OF_MONTH, 0);
calendar.set(Calendar.DAY_OF_WEEK, week);
/**处理未来时间倾向 @author kexm*/
preferFutureWeek(week, calendar);
}
if (week == 7)
week = 1;
else
week++;
calendar.add(Calendar.WEEK_OF_MONTH, 0);
calendar.set(Calendar.DAY_OF_WEEK, week);
/**处理未来时间倾向 @author kexm*/
preferFutureWeek(week, calendar);
}


String s = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(calendar.getTime());
String[] time_fin = s.split("-");
if (flag[0] || flag[1] || flag[2]) {
Expand Down