-
Notifications
You must be signed in to change notification settings - Fork 164
Hi TN Electronic: Fix partial TSV matching, chemical formula logic, and relative file paths #425
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
Open
shrpawar-alt
wants to merge
3
commits into
NVIDIA:staging/hi_tn_v3
Choose a base branch
from
shrpawar-alt:hi-tn-electronic-v2
base: staging/hi_tn_v3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+136
−80
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
37 changes: 37 additions & 0 deletions
37
nemo_text_processing/text_normalization/hi/data/electronic/chemical_names.tsv
This file contains hidden or 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,37 @@ | ||
| H2O जल | ||
| H₂O जल | ||
| CO2 कार्बन डाइऑक्साइड | ||
| CO₂ कार्बन डाइऑक्साइड | ||
| O2 ऑक्सीजन | ||
| O₂ ऑक्सीजन | ||
| N2 नाइट्रोजन | ||
| N₂ नाइट्रोजन | ||
| NaCl सोडियम क्लोराइड | ||
| HCl हाइड्रोक्लोरिक एसिड | ||
| H2SO4 सल्फ्यूरिक एसिड | ||
| H₂SO₄ सल्फ्यूरिक एसिड | ||
| HNO3 नाइट्रिक एसिड | ||
| HNO₃ नाइट्रिक एसिड | ||
| NH3 अमोनिया | ||
| NH₃ अमोनिया | ||
| CH4 मीथेन | ||
| CH₄ मीथेन | ||
| NaOH सोडियम हाइड्रॉक्साइड | ||
| KOH पोटेशियम हाइड्रॉक्साइड | ||
| Ca(OH)2 कैल्शियम हाइड्रॉक्साइड | ||
| Ca(OH)₂ कैल्शियम हाइड्रॉक्साइड | ||
| CaCO3 कैल्शियम कार्बोनेट | ||
| CaCO₃ कैल्शियम कार्बोनेट | ||
| C6H12O6 ग्लूकोज़ | ||
| C₆H₁₂O₆ ग्लूकोज़ | ||
| NaHCO3 सोडियम बाइकार्बोनेट | ||
| NaHCO₃ सोडियम बाइकार्बोनेट | ||
| Na2CO3 सोडियम कार्बोनेट | ||
| Na₂CO₃ सोडियम कार्बोनेट | ||
| CH₃COO– एसीटेट आयन | ||
| CH3COO- एसीटेट आयन | ||
| CH₃COO⁻ एसीटेट आयन | ||
| Ba(OH)2 बेरियम हाइड्रॉक्साइड | ||
| Ba(OH)₂ बेरियम हाइड्रॉक्साइड | ||
| Al2(SO4)3 एल्युमिनियम सल्फेट | ||
| Al₂(SO₄)₃ एल्युमिनियम सल्फेट | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ class ElectronicFst(GraphFst): | |
| e.g. [email protected] -> tokens { electronic { username: "kumar" domain: "gmail.com" } } | ||
| e.g. https://google.com/ -> tokens { electronic { protocol: "https" domain: "google.com/" } } | ||
| e.g. C:\\Users\\HP\\Desktop -> tokens { electronic { path: "C:\\Users\\HP\\Desktop" } } | ||
| e.g. 192.168.1.1 -> tokens { electronic { ip: "192.168.1.1" } } | ||
| e.g. 192.168.1.1 -> tokens { electronic { domain: "192.168.1.1" } } | ||
|
|
||
| """ | ||
|
|
||
|
|
@@ -39,7 +39,6 @@ def __init__(self, deterministic: bool = True): | |
|
|
||
| alphanumeric = NEMO_ALPHA | NEMO_DIGIT | NEMO_HI_DIGIT | subscript_digit | ||
|
|
||
| username_chars = NEMO_ALPHA | NEMO_DIGIT | pynini.accep(".") | pynini.accep("-") | pynini.accep("_") | ||
| username = pynutil.insert("username: \"") + pynini.closure(username_chars, 1) + pynutil.insert("\"") | ||
|
|
||
|
|
@@ -48,7 +47,6 @@ def __init__(self, deterministic: bool = True): | |
|
|
||
| email_graph = username + pynini.cross("@", "") + domain | ||
|
|
||
| # url: protocol handling for https://, http://, www., and combined forms | ||
| protocol_start = pynini.cross("https://", "https") | pynini.cross("http://", "http") | ||
| protocol_end = pynini.cross("www.", "www") | ||
| protocol = ( | ||
|
|
@@ -80,7 +78,6 @@ def __init__(self, deterministic: bool = True): | |
|
|
||
| url_graph = protocol + url_domain | ||
|
|
||
| # file paths: Windows (C:\...), Unix (/...), and backslash-prefixed (\...) | ||
| drive_letter = NEMO_ALPHA | ||
| windows_path_chars = alphanumeric | pynini.union( | ||
| pynini.accep("\\"), | ||
|
|
@@ -107,9 +104,20 @@ def __init__(self, deterministic: bool = True): | |
| pynini.accep("_"), | ||
| pynini.accep("$"), | ||
| ) | ||
| unix_path = ( | ||
| pynutil.insert("path: \"") + pynini.accep("/") + pynini.closure(unix_path_chars, 1) + pynutil.insert("\"") | ||
|
|
||
| unix_segment_chars = alphanumeric | pynini.union( | ||
| pynini.accep("."), | ||
|
Collaborator
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. let's add these with a tsv instead of hardcoding |
||
| pynini.accep("-"), | ||
| pynini.accep("_"), | ||
| pynini.accep("$"), | ||
| ) | ||
| unix_segment = pynini.closure(unix_segment_chars, 1) | ||
|
|
||
| abs_unix_path = pynini.accep("/") + pynini.closure(unix_path_chars, 1) | ||
|
|
||
| rel_unix_path = unix_segment + pynini.accep("/") + pynini.closure(unix_path_chars, 0) | ||
|
|
||
| unix_path = pynutil.insert("path: \"") + (abs_unix_path | rel_unix_path) + pynutil.insert("\"") | ||
|
|
||
| backslash_path_chars = alphanumeric | pynini.union( | ||
| pynini.accep("\\"), | ||
|
|
@@ -125,12 +133,10 @@ def __init__(self, deterministic: bool = True): | |
| + pynutil.insert("\"") | ||
| ) | ||
|
|
||
| # ip addresses: exactly 4 dot-separated octets | ||
| ip_octet = pynini.closure(NEMO_DIGIT, 1, 3) | ||
| dot_octet = pynini.accep(".") + ip_octet | ||
| ip_address = pynutil.insert("domain: \"") + ip_octet + pynini.closure(dot_octet, 3, 3) + pynutil.insert("\"") | ||
|
|
||
| # domains: simple TLD-based (abc.com) and government/education suffixes (.gov.in, .ac.in) | ||
| domain_segment_chars = NEMO_ALPHA | NEMO_DIGIT | pynini.accep("-") | ||
| domain_segment = pynini.closure(domain_segment_chars, 1) | ||
|
|
||
|
|
@@ -144,7 +150,6 @@ def __init__(self, deterministic: bool = True): | |
| pynutil.insert("domain: \"") + domain_body + pynini.closure(pynini.accep("/"), 0, 1) + pynutil.insert("\"") | ||
| ) | ||
|
|
||
| # file extensions: e.g. report.pdf, data.csv | ||
| known_extensions = pynini.project( | ||
| pynini.string_file(get_abs_path("data/electronic/file_extensions.tsv")), "input" | ||
| ) | ||
|
|
@@ -154,27 +159,46 @@ def __init__(self, deterministic: bool = True): | |
| pynutil.insert("domain: \"") + filename_stem + pynini.accep(".") + known_extensions + pynutil.insert("\"") | ||
| ) | ||
|
|
||
| # chemical formulas with subscript digits: e.g. H₂O, CO₂ | ||
| chemical_chars = NEMO_ALPHA | subscript_digit | ||
| chemical_formula = ( | ||
| pynutil.insert("domain: \"") + NEMO_ALPHA + pynini.closure(chemical_chars, 1) + pynutil.insert("\"") | ||
| chemical_chars = ( | ||
| NEMO_ALPHA | ||
| | NEMO_DIGIT | ||
| | subscript_digit | ||
| | pynini.accep("(") | ||
| | pynini.accep(")") | ||
| | pynini.accep("+") | ||
| | pynini.accep("-") | ||
| | pynini.accep("–") | ||
| ) | ||
|
|
||
| # alphanumeric codes: strings containing both letters and digits, | ||
| # optionally separated by hyphens, e.g. IELF004, N95, GSAT-18, F-35B | ||
| raw_chemical = NEMO_ALPHA + pynini.closure(chemical_chars, 1) | ||
|
|
||
| any_chem = pynini.closure(chemical_chars) | ||
| has_open = any_chem + pynini.accep("(") + any_chem | ||
| no_open = pynini.difference(any_chem, has_open) | ||
| ends_with_close = any_chem + pynini.accep(")") | ||
|
|
||
| unbalanced_trailing = pynini.intersect(no_open, ends_with_close) | ||
|
|
||
| valid_chemical = pynini.difference(raw_chemical, unbalanced_trailing).optimize() | ||
|
|
||
| chemical_formula = pynutil.insert("domain: \"") + valid_chemical + pynutil.insert("\"") | ||
|
|
||
| alnum_seg = pynini.closure(NEMO_ALPHA | NEMO_DIGIT, 1) | ||
| alphanumeric_pattern = alnum_seg + pynini.closure(pynini.accep("-") + alnum_seg) | ||
|
|
||
| alnum_hyp_sigma = pynini.closure(NEMO_ALPHA | NEMO_DIGIT | pynini.accep("-")) | ||
| contains_alpha = alnum_hyp_sigma + NEMO_ALPHA + alnum_hyp_sigma | ||
| contains_digit = alnum_hyp_sigma + NEMO_DIGIT + alnum_hyp_sigma | ||
| separator = pynini.accep("-") | pynini.accep(".") | ||
| alphanumeric_pattern = alnum_seg + pynini.closure(separator + alnum_seg) | ||
|
|
||
| alnum_hyp_dot_sigma = pynini.closure(NEMO_ALPHA | NEMO_DIGIT | pynini.accep("-") | pynini.accep(".")) | ||
|
|
||
| contains_alpha = alnum_hyp_dot_sigma + NEMO_ALPHA + alnum_hyp_dot_sigma | ||
| contains_digit = alnum_hyp_dot_sigma + NEMO_DIGIT + alnum_hyp_dot_sigma | ||
|
|
||
| alphanumeric_code_fst = pynini.intersect( | ||
| pynini.intersect(alphanumeric_pattern, contains_alpha), contains_digit | ||
| ).optimize() | ||
|
|
||
| alphanumeric_code = pynutil.insert("domain: \"") + alphanumeric_code_fst + pynutil.insert("\"") | ||
|
|
||
| # Weights use 3 tiers: structurally unambiguous (1.0), moderately general (1.1), greedy (1.2) | ||
| graph = ( | ||
| pynutil.add_weight(url_graph, 1.0) | ||
| | pynutil.add_weight(email_graph, 1.0) | ||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -57,4 +57,9 @@ ip address 192.168.1.1~आई पी एड्रेस एक नौ दो ड | |
| ip address 10.0.0.1~आई पी एड्रेस एक शून्य डॉट शून्य डॉट शून्य डॉट एक | ||
| report.pdf~आर ई पी ओ आर टी डॉट पी डी एफ | ||
| photo.jpg~पी एच ओ टी ओ डॉट जे पी जी | ||
| data.csv~डेटा डॉट सी एस वी | ||
| data.csv~डेटा डॉट सी एस वी | ||
| robinson.org~आर ओ बी आई एन एस ओ एन डॉट ऑर्ग | ||
| [email protected]~ए एन ए एन डी एट जीमेल डॉट कॉम | ||
| Al₂(SO₄)₃~एल्युमिनियम सल्फेट | ||
| C₂H₄~सी दो एच चार | ||
| home/desktop~होम फॉरवर्ड स्लैश डेस्कटॉप | ||
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.
it doesn't make sense to hardcode some chemical compounds and not cover others. if we want coverage for this, it would make more sense to have all individual elements and rules to cover their composition