OPENNLP-1930: Regex removal (2/10): Parse Arvores Deitadas markup with cursor scans - #1276
Conversation
f2fbb71 to
beac8cd
Compare
This comment was marked as outdated.
This comment was marked as outdated.
1 similar comment
|
Here are some additional comments. We ran all AD streams (sentence, name, POS, chunk, raw tree, detokenized tokens) over the real Bosque_CF_8.0 and FlorestaVirgem_CF_3.0 corpora with main, #1275 and this PR. This PR changes nothing there: every stream is byte-identical to #1275, and the Blocking
Minor
Verified:
|
This comment was marked as outdated.
This comment was marked as outdated.
7f14665 to
dcc5e4c
Compare
|
CI is red. |
|
#1275 is split up and closed. The AD reader changes it carried (ADNameSampleStream, ADPOSSampleStream, ADSentenceStream, ADSentenceSampleStream, their tests and the AD paragraph of the corpora chapter) now belong to this PR, which already contains them. Please rebase onto #1311 (part 1) instead of the old #1275 branch. |
The AD corpus readers no longer use regular expressions. This includes the reader changes split out of OPENNLP-1928 (apache#1275): ADNameSampleStream, ADPOSSampleStream, ADSentenceSampleStream and ADSentenceStream replace their tag, whitespace, underline, hyphen, alphanumeric, metadata and punctuation patterns with character scans over the StringUtil helpers. ADSentenceStream.SentenceParser reads node, leaf and bizarre-leaf lines and the fallback check with cursor scans, ADSentenceStream recognizes the sentence, title, box, paragraph and text tags by name, and the package-private ADMetadata reads the text id, the paragraph id and the source for ADNameSampleStream and ADSentenceSampleStream. The scans follow the format, not the accidents of the old patterns: an AD tree line without a tag keeps its full lexeme, the first lexeme character is no longer lost, paren-in-group node tails and quoted-bracket tags are read, and whitespace follows the Unicode definition. Hyphenated words are preserved by default; the ADTokenSampleStreamFactory option and the CLI chapter describe the switch. A leaf without a functional tag in ADChunkSampleStream is tagged with its lexeme, as the POS reader does. The corpora chapter states the reader contract. On the real corpora the output is unchanged: all AD streams over Bosque_CF_8.0 and FlorestaVirgem_CF_3.0 are byte-identical to the previous readers, and the ArvoresDeitadasEval training data hashes are the same. Squashed from the review rounds of apache#1276 for the rebase onto apache#1311.
2116ec0 to
d7911d7
Compare
|
I'm running eval locally, if that's green I'll push |
The AD corpus readers no longer use regular expressions. This includes the reader changes split out of OPENNLP-1928 (apache#1275): ADNameSampleStream, ADPOSSampleStream, ADSentenceSampleStream and ADSentenceStream replace their tag, whitespace, underline, hyphen, alphanumeric, metadata and punctuation patterns with character scans over the StringUtil helpers. ADSentenceStream.SentenceParser reads node, leaf and bizarre-leaf lines and the fallback check with cursor scans, ADSentenceStream recognizes the sentence, title, box, paragraph and text tags by name, and the package-private ADMetadata reads the text id, the paragraph id and the source for ADNameSampleStream and ADSentenceSampleStream. The scans follow the format, not the accidents of the old patterns: an AD tree line without a tag keeps its full lexeme, the first lexeme character is no longer lost, paren-in-group node tails and quoted-bracket tags are read, and whitespace follows the Unicode definition. Hyphenated words are preserved by default; the ADTokenSampleStreamFactory option and the CLI chapter describe the switch. A leaf without a functional tag in ADChunkSampleStream is tagged with its lexeme, as the POS reader does. The corpora chapter states the reader contract. On the real corpora the output is unchanged: all AD streams over Bosque_CF_8.0 and FlorestaVirgem_CF_3.0 are byte-identical to the previous readers, and the ArvoresDeitadasEval training data hashes are the same. Squashed from the review rounds of apache#1276 for the rebase onto apache#1311.
d7911d7 to
db074e8
Compare
Pleasae rebase this one on latest main. This will be next in the Regex queue. |
The AD corpus readers no longer use regular expressions. This includes the reader changes split out of OPENNLP-1928 (apache#1275): ADNameSampleStream, ADPOSSampleStream, ADSentenceSampleStream and ADSentenceStream replace their tag, whitespace, underline, hyphen, alphanumeric, metadata and punctuation patterns with character scans over the StringUtil helpers. ADSentenceStream.SentenceParser reads node, leaf and bizarre-leaf lines and the fallback check with cursor scans, ADSentenceStream recognizes the sentence, title, box, paragraph and text tags by name, and the package-private ADMetadata reads the text id, the paragraph id and the source for ADNameSampleStream and ADSentenceSampleStream. The scans follow the format, not the accidents of the old patterns: an AD tree line without a tag keeps its full lexeme, the first lexeme character is no longer lost, paren-in-group node tails and quoted-bracket tags are read, and whitespace follows the Unicode definition. Hyphenated words are preserved by default; the ADTokenSampleStreamFactory option and the CLI chapter describe the switch. A leaf without a functional tag in ADChunkSampleStream is tagged with its lexeme, as the POS reader does. The corpora chapter states the reader contract. On the real corpora the output is unchanged: all AD streams over Bosque_CF_8.0 and FlorestaVirgem_CF_3.0 are byte-identical to the previous readers, and the ArvoresDeitadasEval training data hashes are the same. Squashed from the review rounds of apache#1276 for the rebase onto apache#1311.
db074e8 to
2def6bf
Compare
|
Thanks for the rebase. The branch is on current main, and the Windows fix (closing the detokenizer dictionary stream) looks right. Blocking
Minor
|
The AD corpus readers no longer use regular expressions. This includes the reader changes split out of OPENNLP-1928 (apache#1275): ADNameSampleStream, ADPOSSampleStream, ADSentenceSampleStream and ADSentenceStream replace their tag, whitespace, underline, hyphen, alphanumeric, metadata and punctuation patterns with character scans over the StringUtil helpers. ADSentenceStream.SentenceParser reads node, leaf and bizarre-leaf lines and the fallback check with cursor scans, ADSentenceStream recognizes the sentence, title, box, paragraph and text tags by name, and the package-private ADMetadata reads the text id, the paragraph id and the source for ADNameSampleStream and ADSentenceSampleStream. The scans follow the format, not the accidents of the old patterns: an AD tree line without a tag keeps its full lexeme, the first lexeme character is no longer lost, paren-in-group node tails and quoted-bracket tags are read, and whitespace follows the Unicode definition. The corpora chapter states the reader contract. On the real corpora the output is unchanged: all AD streams over Bosque_CF_8.0 and FlorestaVirgem_CF_3.0 are byte-identical to the previous readers, and the ArvoresDeitadasEval training data hashes are the same. Squashed from the review rounds of apache#1276 for the rebase onto current main.
2def6bf to
3341ec2
Compare
The AD corpus readers no longer use regular expressions. This includes the reader changes split out of OPENNLP-1928 (apache#1275): ADNameSampleStream, ADPOSSampleStream, ADSentenceSampleStream and ADSentenceStream replace their tag, whitespace, underline, hyphen, alphanumeric, metadata and punctuation patterns with character scans over the StringUtil helpers. ADSentenceStream.SentenceParser reads node, leaf and bizarre-leaf lines and the fallback check with cursor scans, ADSentenceStream recognizes the sentence, title, box, paragraph and text tags by name, and the package-private ADMetadata reads the text id, the paragraph id and the source for ADNameSampleStream and ADSentenceSampleStream. The scans follow the format, not the accidents of the old patterns: an AD tree line without a tag keeps its full lexeme, the first lexeme character is no longer lost, paren-in-group node tails and quoted-bracket tags are read, and whitespace follows the Unicode definition. The corpora chapter states the reader contract. On the real corpora the sentence samples are unchanged: the verifyTrainingData hashes of ArvoresDeitadasEval stay the same for Bosque_CF_8.0 and FlorestaVirgem_CF_3.0. The tree, name, POS and chunk streams differ in 2 Bosque and 86 Floresta samples, all from the reader bug fixes above: tag fragments such as .vp and <ARGOpp no longer appear as lexemes, and the first character or the whole lexeme of a tag-less tree line is no longer lost (P: reads DP, CJT: reads CJT, and the =H==( and =H===( lines contribute ( again). Squashed from the review rounds of apache#1276 for the rebase onto current main.
3341ec2 to
60cf48d
Compare
|
Moved this to draft. The split would be a stack, so I just need more time to think about it - it's not a big scope either - but I'll let it remain in draft for this reason. It won't take long to do. I think this is mergable now but I won't flip it back until I test the new PR/JIRA. It's just a quick methodical way to do it. (it might only take an hour to fix though, so likely when everyone sees this message it'll probably be green anyway) |
60cf48d to
d556ac4
Compare
|
Separation done. It's stacked, so I'll open a PR once this is merged - it's also ready to go https://github.com/ai-pipestream/opennlp/pull/new/OPENNLP-1984-ad-hyphen-default I'll open the new one as soon as this is merged. I'll do another pass of the remaining PRs. Please let me know if you catch any, let me know and I'll do the same surgery. Thank you @rzo1 and @mawiesne for your patience on this - greatly appreciate it. |
|
Thanks for the split. The hyphen default, A few things are still open:
Once these are sorted, it's good from my side. @mawiesne, could you take a look as well? |
The AD corpus readers no longer use regular expressions. This includes the reader changes split out of OPENNLP-1928 (apache#1275): ADNameSampleStream, ADPOSSampleStream, ADSentenceSampleStream and ADSentenceStream replace their tag, whitespace, underline, hyphen, alphanumeric, metadata and punctuation patterns with character scans over the StringUtil helpers. ADSentenceStream.SentenceParser reads node, leaf and bizarre-leaf lines and the fallback check with cursor scans, ADSentenceStream recognizes the sentence, title, box, paragraph and text tags by name, and the package-private ADMetadata reads the text id, the paragraph id and the source for ADNameSampleStream and ADSentenceSampleStream. The scans follow the format, not the accidents of the old patterns: an AD tree line without a tag keeps its full lexeme, the first lexeme character is no longer lost, paren-in-group node tails and quoted-bracket tags are read, and whitespace follows the Unicode definition. The corpora chapter states the reader contract. On the real corpora the sentence samples are unchanged: the verifyTrainingData hashes of ArvoresDeitadasEval stay the same for Bosque_CF_8.0 and FlorestaVirgem_CF_3.0. The tree, name, POS and chunk streams differ in 2 Bosque and 86 Floresta samples, all from the reader bug fixes above: tag fragments such as .vp and <ARGOpp no longer appear as lexemes, and the first character or the whole lexeme of a tag-less tree line is no longer lost (P: reads DP, CJT: reads CJT, and the =H==( and =H===( lines contribute ( again). Squashed from the review rounds of apache#1276 for the rebase onto current main.
DetokenizerSampleStreamFactory.createDetokenizer left the dictionary FileInputStream open, so JUnit TempDir cleanup failed on Windows for ADHyphenatedTokenTest: 'detokenizer.xml: The process cannot access the file because it is being used by another process' (27 errors, Windows jobs of run 35343354338). The dictionary reads the stream fully in its constructor, so close it there.
The review asked to put back the dropped reject cases 'CF_1001 p=2' and 'CF 1001 p=2' (the text id follows the leading letters and hyphens directly). Also pin U+2029, which the corpora chapter documents as read like U+2028.
…ld boundary
The leaf scans searched backward from the end of the line, so a lemma
extended to the last quote after which the rest still parsed, the
greedy behavior of the replaced patterns: =H:n("x" M S)<tab>a') b
produced lemma 'x" M S)<tab>a', no morphology, and lexeme 'b'. Now the
first matching quote followed by whitespace, a secondary tag, or a
closing bracket closes the field, giving lemma 'x', morphology 'M S',
and lexeme 'a') b'. Later quotes are not tried, so a line that does not
parse after that quote becomes a fallback leaf. Quotes inside a word
remain part of the lemma, and the square bracket after some Floresta
time and measurement lemmas is accepted.
Red: 7 assertion failures over 247 parser cases. Passing: 500 focused
AD cases. No parsed field changed for the 920,203 quoted tree-line
candidates in Bosque and FlorestaVirgem. The manual documents the lemma
boundary rule.
d556ac4 to
d3c2e06
Compare
|
https://ci-builds.apache.org/job/OpenNLP/job/eval-tests-configurable/81/ failed. Needs an value update. Improvment: ArvoresDeitadasEval.evalPortugueseChunkerPerceptron:190->chunkerCrossEval:138 expected: <0.9631066789979492> but was: <0.963736197429554> |
…ected reader Eval build 81 of eval-tests-configurable failed one assertion on this branch: ArvoresDeitadasEval.evalPortugueseChunkerPerceptron expected 0.9631066789979492 and got 0.963736197429554. The other 14 Arvores Deitadas runs, among them the GIS, QN and naive Bayes chunker runs, passed at their expected values. The change comes from 2 Bosque node lines with tags joined by a stray separator, =====P.vp and ========N<ARGOpp. The old reader lost the first character of a tag-less tree line and put .vp and <ARGOpp into 2 sentences as words of an NP chunk. The reader on this branch reads them as tag-less lines with markup and adds no token. A dump of every Bosque chunk sample from main and from this branch (4212 samples each) shows no other difference than these 3 tokens. ADChunkSampleStreamTest.testNodeLineWithStraySeparatorAddsNoToken records that reading. Red on main: expected [que, teria, de, .] but was [que, .vp, teria, <ARGOpp, de, .]. Passes on this branch. The perceptron value is updated to the one the build got. Local runs with the same Bosque file (md5 b69a3b82c385741cd876d166878b52e8) reproduce 0.9631066789979492 on main and 0.963736197429554 on this branch.
|
EVAL is FINE now. |
|
It's green again |
Replaces the regular expressions in the Arvores Deitadas (AD) corpus readers with cursor-based character scans built on the
StringUtilhelpers. This PR also carries the AD reader changes that were split out of #1275.The hyphen-splitting default change (
splitHyphenatedTokens),ADDetokenizer,ADHyphenatedTokenTestandevalPortugueseTokenizerDefaultNaiveBayesare not in this PR. They moved to OPENNLP-1984, a separate stacked PR that will be opened after this one is merged.Changes
ADSentenceStream: the markup patterns (<s>,</s>,<p>,<t>,</t>,<caixa>,</caixa>,<ext>,</ext>) are replaced by exact tag-name checks.SentenceParserreads node, leaf, bizarre-leaf and punctuation lines, and the fallback check, with cursor scans. The»+ whitespace +./,cleanup no longer uses a regex.ADNameSampleStream: the NER tag, whitespace, underscore, hyphen and alphanumeric patterns are replaced bytagContent,StringUtil.splitOnUnicodeWhitespace,splitOnUnderscores,matchHyphenatedTokenandisAlphaNumeric.getTextIDreads its ids throughADMetadata.ADPOSSampleStream: POS tags that contain whitespace are joined with=byreplaceWhitespaceWithEqualsinstead of\s+.ADSentenceSampleStream: the text and paragraph ids come fromADMetadata.parseTextAndParagraphinstead ofMETA_1.ADMetadata: reads the text id, paragraph id, text prefix (LIT) andsourceattribute (CIE). An id that does not fit into anintcounts as invalid metadata.DetokenizerSampleStreamFactory: closes the detokenizer dictionary input stream after loading. Before this, JUnit@TempDircleanup failed on Windows.corpora.xml: documents the AD reader contract, including the whitespace definition, markup tags, the lemma boundary, tag-less tree lines, metadata ids and punctuation lines.Behavior changes
The scans follow the format rather than quirks of the old patterns:
=H:n("x" M S)<tab>a') bnow gives lemmax, morphologyM Sand lexemea') b. Before, it gave lemmax" M S)<tab>a, no morphology and lexemeb. If the rest of the line does not parse after that quote, the line becomes a fallback leaf. Quotes inside a word stay part of the lemma.<sx>and a self-closing<s/>are not sentence tags.Validation
ADSentenceStreamTest248,ADMetadataTest87,ADNameSampleStreamTest84 test runs; all 472 tests inopennlp.tools.formats.adpass.ArvoresDeitadasEvalon Bosque_CF_8.0 and FlorestaVirgem_CF_3.0: theverifyTrainingDatahashes of the sentence samples are unchanged. The tree, name, POS and chunk streams differ in 2 Bosque and 86 Floresta samples. All of these differences come from the reader fixes above: tag fragments such as.vpand<ARGOppno longer appear as lexemes, and tag-less tree lines keep their text (P:readsDP,CJT:readsCJT, and the=H==(and=H===(lines contribute(again).ArvoresDeitadasEvalare unchanged in this PR.OPENNLP-1930