-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from nlpsandbox/ymnliu-develop
Update API to version 0.2.2
- Loading branch information
Showing
39 changed files
with
912 additions
and
1,509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules | ||
.idea | ||
venv | ||
venv | ||
dist.yaml | ||
openapi.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "date-annotator-example-java", | ||
"version": "0.2.2", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@openapitools/openapi-generator-cli": "^1.0.18-4.3.1" | ||
}, | ||
"scripts": { | ||
"generate:server": "openapi-generator generate -g spring -o server -i $npm_config_spec" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,5 @@ | |
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md | ||
|
||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
README.md | ||
pom.xml | ||
src/main/java/org/openapitools/OpenAPI2SpringBoot.java | ||
src/main/java/org/openapitools/RFC3339DateFormat.java | ||
src/main/java/org/openapitools/api/ApiUtil.java | ||
src/main/java/org/openapitools/api/ServiceApi.java | ||
src/main/java/org/openapitools/api/ServiceApiController.java | ||
src/main/java/org/openapitools/api/TextDateAnnotationsApi.java | ||
src/main/java/org/openapitools/api/TextDateAnnotationsApiController.java | ||
src/main/java/org/openapitools/configuration/HomeController.java | ||
src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java | ||
src/main/java/org/openapitools/model/Error.java | ||
src/main/java/org/openapitools/model/Note.java | ||
src/main/java/org/openapitools/model/Service.java | ||
src/main/java/org/openapitools/model/TextAnnotation.java | ||
src/main/java/org/openapitools/model/TextDateAnnotation.java | ||
src/main/java/org/openapitools/model/TextDateAnnotationAllOf.java | ||
src/main/java/org/openapitools/model/TextDateAnnotationRequest.java | ||
src/main/java/org/openapitools/model/TextDateAnnotations.java | ||
src/main/resources/application.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4.3.1 | ||
5.0.0-beta2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.nlpsandbox; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.openapitools.model.TextDateAnnotation; | ||
|
||
public class DateExtractor { | ||
|
||
class NamedPattern{ | ||
public String name; | ||
public Pattern pattern; | ||
|
||
public NamedPattern(String name, Pattern pattern){ | ||
this.name = name; | ||
this.pattern = pattern; | ||
} | ||
} | ||
|
||
class Span{ | ||
int begin; | ||
int end; | ||
int length; | ||
|
||
public Span(int begin, int end){ | ||
this.begin = begin; | ||
this.end = end; | ||
this.length = end - begin; | ||
} | ||
} | ||
|
||
static List<NamedPattern> datePatterns; | ||
|
||
public DateExtractor(){ | ||
datePatterns = new ArrayList<>(); | ||
datePatterns.add(new NamedPattern("DD/MM/YYYY", | ||
Pattern.compile( | ||
"\\b([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])(/)([1-9]|0[1-9]|1[0-2])(/)(19[0-9][0-9]|20[0-9][0-9])"))); | ||
|
||
datePatterns.add(new NamedPattern("MM/DD/YYYY", | ||
Pattern.compile( | ||
"\\b([1-9]|0[1-9]|1[0-2])(/)([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])(/)(19[0-9][0-9]|20[0-9][0-9])"))); | ||
|
||
datePatterns.add(new NamedPattern("MM-DD-YYYY", | ||
Pattern.compile( | ||
"\\b([1-9]|0[1-9]|1[0-2])(-)([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])(-)(19[0-9][0-9]|20[0-9][0-9])"))); | ||
|
||
datePatterns.add(new NamedPattern("MMMM", | ||
Pattern.compile("\\b(January|February|March|April|May|June|" + | ||
"July|August|September|October|November|" + | ||
"December)"))); | ||
} | ||
|
||
public List<TextDateAnnotation> findDatesFromString(String sentence){ | ||
|
||
List<TextDateAnnotation> annotations = new ArrayList<>(); | ||
for (NamedPattern np: datePatterns) { | ||
// Now create matcher object. | ||
Matcher m = np.pattern.matcher(sentence); | ||
while (m.find()) { | ||
annotations.add(new TextDateAnnotation() | ||
.start(m.start(0)) | ||
.length(m.group(0).length()) | ||
.text(m.group(0)) | ||
.dateFormat(np.name) | ||
.confidence(92.5f)); | ||
} | ||
} | ||
return annotations; | ||
} | ||
|
||
public static void main(String[] args) { | ||
DateExtractor de = new DateExtractor(); | ||
String str1 = "Today is 10/26/2020, and yesterday is 10/25/2020. "; | ||
de.findDatesFromString(str1); | ||
|
||
String str2 = "Today is 26/11/2020. "; | ||
de.findDatesFromString(str2); | ||
} | ||
} |
32 changes: 24 additions & 8 deletions
32
server/src/main/java/org/openapitools/RFC3339DateFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
package org.openapitools; | ||
|
||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat; | ||
import com.fasterxml.jackson.databind.util.ISO8601Utils; | ||
import com.fasterxml.jackson.databind.util.StdDateFormat; | ||
|
||
import java.text.DateFormat; | ||
import java.text.FieldPosition; | ||
import java.text.ParsePosition; | ||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
import java.util.TimeZone; | ||
|
||
public class RFC3339DateFormat extends DateFormat { | ||
private static final long serialVersionUID = 1L; | ||
private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); | ||
|
||
public class RFC3339DateFormat extends ISO8601DateFormat { | ||
private final StdDateFormat fmt = new StdDateFormat() | ||
.withTimeZone(TIMEZONE_Z) | ||
.withColonInTimeZone(true); | ||
|
||
private static final long serialVersionUID = 1L; | ||
public RFC3339DateFormat() { | ||
this.calendar = new GregorianCalendar(); | ||
} | ||
|
||
@Override | ||
public Date parse(String source, ParsePosition pos) { | ||
return fmt.parse(source, pos); | ||
} | ||
|
||
// Same as ISO8601DateFormat but serializing milliseconds. | ||
@Override | ||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { | ||
String value = ISO8601Utils.format(date, true); | ||
toAppendTo.append(value); | ||
return toAppendTo; | ||
return fmt.format(date, toAppendTo, fieldPosition); | ||
} | ||
|
||
@Override | ||
public Object clone() { | ||
return this; | ||
} | ||
} |
Oops, something went wrong.