-
Notifications
You must be signed in to change notification settings - Fork 100
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
more norms #649
Merged
Merged
more norms #649
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2a1767b
saving intermediate progress on more numeric normalization
maxaalexeeva 66ee8a4
more normalization + tests
maxaalexeeva 442abcb
correcting mention tok interval + cleanup
maxaalexeeva d1178f3
removed wrong commas
maxaalexeeva e7915a5
added another way to write mg/l
maxaalexeeva 7f5d111
added more numeric tests + small rule adjustments
maxaalexeeva a56e7a4
more specific years to avoid capturing 2700-2800 as date
maxaalexeeva 39a53f0
temporary printouts
maxaalexeeva 2b935c6
a convoluted method to fix the Sahel 108 in(ch) Senegal error
maxaalexeeva 097c898
cleanup
maxaalexeeva 526bf2a
updating version to that in main
maxaalexeeva 9b7335c
Merge branch 'master' into masha-norms
maxaalexeeva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -16,7 +16,24 @@ class NumericActions(seasonNormalizer: SeasonNormalizer) extends Actions { | |
val convertedMentions = new ArrayBuffer[Mention]() | ||
for(m <- mentions) { | ||
try { | ||
convertedMentions += converter(m) | ||
convertedMentions += converter(m ) | ||
} catch { | ||
case e: Exception => | ||
// sometimes these conversions fail, mainly on broken texts | ||
// let's be robust here: report the error and move on | ||
System.err.println(s"WARNING: $converterName conversion failed! Recovering and continuing...") | ||
e.printStackTrace() | ||
} | ||
} | ||
convertedMentions | ||
} | ||
Comment on lines
+19
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't necessary, but one way to do it without the buffer is for {
m <- mentions
converted <- Try(converter(m))
.recover { case throwable: Throwable =>
System.err.println(s"WARNING: $converterName conversion failed! Recovering and continuing...")
throwable.printStackTrace()
Seq.empty[Mention]
}
.get
} yield converted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. With processors I basically go the path of fewest changes :) |
||
|
||
/** Converts a sequence of mentions to new types given the converter function */ | ||
private def convertWithOneToManyConverter(mentions: Seq[Mention], converter: Mention => Seq[Mention], converterName: String): Seq[Mention] = { | ||
val convertedMentions = new ArrayBuffer[Mention]() | ||
for(m <- mentions) { | ||
try { | ||
convertedMentions ++= converter(m ) | ||
} catch { | ||
case e: Exception => | ||
// sometimes these conversions fail, mainly on broken texts | ||
|
@@ -38,6 +55,11 @@ class NumericActions(seasonNormalizer: SeasonNormalizer) extends Actions { | |
convert(mentions, toMeasurementMention, "toMeasurementMention") | ||
} | ||
|
||
/** Constructs a MeasurementMention from a token pattern */ | ||
def mkSharedMeasurementMention(mentions: Seq[Mention], state: State): Seq[Mention] = { | ||
convertWithOneToManyConverter(mentions, toSharedMeasurementMention, "toSharedMeasurementMention") | ||
} | ||
|
||
def mkPercentage(mentions: Seq[Mention], state: State): Seq[Mention] = { | ||
convert(mentions, toPercentageMention, "toPercentageMention") | ||
} | ||
|
@@ -120,6 +142,11 @@ class NumericActions(seasonNormalizer: SeasonNormalizer) extends Actions { | |
convert(mentions, toDateRangeMentionFromVagueSeason, "mkDateRangeMentionVagueSeason") | ||
} | ||
|
||
/** Constructs a DateRangeMention from a token pattern */ | ||
def mkDateRangeMentionOneTokenYearRange(mentions: Seq[Mention], state: State): Seq[Mention] = { | ||
convert(mentions, toDateRangeMentionFromOneTokenYearRange, "mkDateRangeMentionOneTokenYearRange") | ||
} | ||
|
||
/** Constructs a DateMention from a token pattern */ | ||
def mkDateMention(mentions: Seq[Mention], state: State): Seq[Mention] = { | ||
convert(mentions, toDateMention, "toDateMention") | ||
|
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably all of processors needs to be reviewed for its use of println, System.out, and System.err. These should probably be logged rather than printed. That's not your problem.