@valueerror/ltjs-lang-it 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/LICENSE +232 -0
  2. package/NOTICE +9 -0
  3. package/README.md +25 -2
  4. package/index.js +5 -0
  5. package/licenses/LGPL-2.1.txt +504 -0
  6. package/licenses/resource_it_README.txt +4 -0
  7. package/licenses/resource_it_hunspell_README_it_IT.txt +313 -0
  8. package/package.json +60 -4
  9. package/resource-root.js +4 -0
  10. package/resources/META-INF/org/languagetool/language-module.properties +1 -0
  11. package/resources/org/languagetool/resource/it/README.txt +4 -0
  12. package/resources/org/languagetool/resource/it/added.txt +12 -0
  13. package/resources/org/languagetool/resource/it/added_custom.txt +4 -0
  14. package/resources/org/languagetool/resource/it/disambiguation.xml +92 -0
  15. package/resources/org/languagetool/resource/it/hunspell/README_it_IT.txt +313 -0
  16. package/resources/org/languagetool/resource/it/hunspell/ignore.txt +2 -0
  17. package/resources/org/languagetool/resource/it/hunspell/it_IT.dict +0 -0
  18. package/resources/org/languagetool/resource/it/hunspell/it_IT.info +8 -0
  19. package/resources/org/languagetool/resource/it/hunspell/spelling.txt +277 -0
  20. package/resources/org/languagetool/resource/it/italian.dict +0 -0
  21. package/resources/org/languagetool/resource/it/italian.info +8 -0
  22. package/resources/org/languagetool/resource/it/italian_synth.dict +0 -0
  23. package/resources/org/languagetool/resource/it/italian_synth.info +8 -0
  24. package/resources/org/languagetool/resource/it/italian_tags.txt +663 -0
  25. package/resources/org/languagetool/resource/it/removed.txt +4 -0
  26. package/resources/org/languagetool/resource/it/removed_custom.txt +4 -0
  27. package/resources/org/languagetool/rules/it/grammar.xml +2199 -0
  28. package/src/lang/it/language/Italian.js +95 -0
  29. package/src/lang/it/rules/DateCheckFilter.js +64 -0
  30. package/src/lang/it/rules/ItalianWordRepeatRule.js +37 -0
  31. package/src/lang/it/rules/MorfologikItalianSpellerRule.js +48 -0
  32. package/src/lang/it/synthesis/ItalianSynthesizer.js +20 -0
  33. package/src/lang/it/tagging/ItalianRuleDisambiguator.js +23 -0
  34. package/src/lang/it/tagging/ItalianTagger.js +16 -0
@@ -0,0 +1,95 @@
1
+ // Java: org.languagetool.language.Italian
2
+ import { LanguageWithModel } from '@valueerror/ltjs-core/src/core/LanguageWithModel.js';
3
+ import { LanguageMaintainedState } from '@valueerror/ltjs-core/src/core/LanguageMaintainedState.js';
4
+ import { Contributor } from '@valueerror/ltjs-core/src/core/language/Contributor.js';
5
+ import { createComponent } from '@valueerror/ltjs-core/src/core/language/components.js';
6
+ import { registerClass } from '@valueerror/ltjs-core/src/core/resources/ClassBroker.js';
7
+ import { SRXSentenceTokenizer } from '@valueerror/ltjs-core/src/core/text/tokenizers/SRXSentenceTokenizer.js';
8
+ import { WhitespaceBeforePunctuationRule } from '@valueerror/ltjs-core/src/core/rules/WhitespaceBeforePunctuationRule.js';
9
+ import { CommaWhitespaceRule } from '@valueerror/ltjs-core/src/core/rules/CommaWhitespaceRule.js';
10
+ import { DoublePunctuationRule } from '@valueerror/ltjs-core/src/core/rules/DoublePunctuationRule.js';
11
+ import { GenericUnpairedBracketsRule } from '@valueerror/ltjs-core/src/core/rules/GenericUnpairedBracketsRule.js';
12
+ import { UppercaseSentenceStartRule } from '@valueerror/ltjs-core/src/core/rules/UppercaseSentenceStartRule.js';
13
+ import { MultipleWhitespaceRule } from '@valueerror/ltjs-core/src/core/rules/MultipleWhitespaceRule.js';
14
+ import { MorfologikItalianSpellerRule } from '../rules/MorfologikItalianSpellerRule.js';
15
+ import { ItalianWordRepeatRule } from '../rules/ItalianWordRepeatRule.js';
16
+ import { ItalianTagger } from '../tagging/ItalianTagger.js';
17
+ import { ItalianSynthesizer } from '../synthesis/ItalianSynthesizer.js';
18
+
19
+ // Java: Italian
20
+ export class Italian extends LanguageWithModel {
21
+ static FQCN = 'org.languagetool.language.Italian';
22
+
23
+ // Java: Italian#getName()
24
+ getName() {
25
+ return 'Italian';
26
+ }
27
+
28
+ // Java: Italian#getShortCode()
29
+ getShortCode() {
30
+ return 'it';
31
+ }
32
+
33
+ // Java: Italian#getCountries()
34
+ getCountries() {
35
+ return ['IT', 'CH'];
36
+ }
37
+
38
+ // Java: Italian#createDefaultTagger()
39
+ createDefaultTagger() {
40
+ return new ItalianTagger();
41
+ }
42
+
43
+ // Java: Italian#createDefaultSentenceTokenizer()
44
+ createDefaultSentenceTokenizer() {
45
+ return new SRXSentenceTokenizer(this);
46
+ }
47
+
48
+ // Java: Italian#getMaintainers()
49
+ getMaintainers() {
50
+ return [new Contributor('Paolo Bianchini')];
51
+ }
52
+
53
+ // Java: Italian#getRelevantRules(ResourceBundle,UserConfig,Language,List)
54
+ getRelevantRules(messages, userConfig, motherTongue, altLanguages) {
55
+ return [
56
+ new WhitespaceBeforePunctuationRule(messages),
57
+ new CommaWhitespaceRule(messages),
58
+ new DoublePunctuationRule(messages),
59
+ new GenericUnpairedBracketsRule(messages,
60
+ ['[', '(', '{', '»', '«'],
61
+ [']', ')', '}', '«', '»']),
62
+ new MorfologikItalianSpellerRule(messages, this, userConfig, altLanguages),
63
+ new UppercaseSentenceStartRule(messages, this),
64
+ new ItalianWordRepeatRule(messages, this),
65
+ new MultipleWhitespaceRule(messages, this),
66
+ ];
67
+ }
68
+
69
+ // Java: Italian#getRelevantLanguageModelRules(ResourceBundle,LanguageModel,UserConfig)
70
+ getRelevantLanguageModelRules() {
71
+ return []; // ItalianConfusionProbabilityRule needs a language model (ngram, DEV-001); DEV-026: null model gives an empty list
72
+ }
73
+
74
+ // Java: Italian#createDefaultDisambiguator()
75
+ createDefaultDisambiguator() {
76
+ return createComponent('org.languagetool.tagging.disambiguation.rules.it.ItalianRuleDisambiguator');
77
+ }
78
+
79
+ // Java: Italian#createDefaultSynthesizer()
80
+ createDefaultSynthesizer() {
81
+ return ItalianSynthesizer.INSTANCE;
82
+ }
83
+
84
+ // Java: Italian#getMaintainedState()
85
+ getMaintainedState() {
86
+ return LanguageMaintainedState.ActivelyMaintained;
87
+ }
88
+
89
+ // Java: Italian#createDefaultSpellingRule(ResourceBundle)
90
+ createDefaultSpellingRule(messages) {
91
+ return new MorfologikItalianSpellerRule(messages, this, null, null);
92
+ }
93
+ }
94
+
95
+ registerClass(Italian.FQCN, Italian);
@@ -0,0 +1,64 @@
1
+ // Java: org.languagetool.rules.it.DateCheckFilter
2
+ import { registerClass } from '@valueerror/ltjs-core/src/core/resources/ClassBroker.js';
3
+ import { Calendar } from '@valueerror/ltjs-core/src/lib/java/Calendar.js';
4
+ import { Locale } from '@valueerror/ltjs-core/src/lib/java/Locale.js';
5
+ import { RuntimeException } from '@valueerror/ltjs-core/src/lib/java/errors.js';
6
+ import { toLowerCase } from '@valueerror/ltjs-core/src/lib/java/strings.js';
7
+ import { AbstractDateCheckFilter } from '@valueerror/ltjs-core/src/core/rules/AbstractDateCheckFilter.js';
8
+
9
+ // Java: DateCheckFilter
10
+ export class DateCheckFilter extends AbstractDateCheckFilter {
11
+ static FQCN = 'org.languagetool.rules.it.DateCheckFilter';
12
+ static JAVA_ABSTRACT = false;
13
+ static JAVA_CONSTRUCTORS = [{ params: [], text: 'public org.languagetool.rules.it.DateCheckFilter()' }];
14
+
15
+ // Java: DateCheckFilter#getCalendar()
16
+ getCalendar() {
17
+ return Calendar.getInstance(Locale.UK);
18
+ }
19
+
20
+ // Java: DateCheckFilter#getDayOfWeek(String) and #getDayOfWeek(Calendar) (overloads, one JS method dispatching on the argument type)
21
+ getDayOfWeek(arg) {
22
+ if (arg instanceof Calendar) {
23
+ const englishDay = arg.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.UK);
24
+ if (englishDay === 'Sunday') return 'domenica';
25
+ if (englishDay === 'Monday') return 'lunedì';
26
+ if (englishDay === 'Tuesday') return 'martedì';
27
+ if (englishDay === 'Wednesday') return 'mercoledì';
28
+ if (englishDay === 'Thursday') return 'giovedì';
29
+ if (englishDay === 'Friday') return 'venerdì';
30
+ if (englishDay === 'Saturday') return 'sabato';
31
+ return '';
32
+ }
33
+ const dayStr = arg;
34
+ const day = toLowerCase(dayStr);
35
+ if (day.startsWith('do') || day === 'domenica') return Calendar.SUNDAY;
36
+ if (day.startsWith('lu') || day === 'lunedì') return Calendar.MONDAY;
37
+ if (day.startsWith('ma') || day === 'martedì') return Calendar.TUESDAY;
38
+ if (day.startsWith('me') || day === 'mercoledì') return Calendar.WEDNESDAY;
39
+ if (day.startsWith('gi') || day === 'giovedì') return Calendar.THURSDAY;
40
+ if (day.startsWith('ve') || day === 'venerdì') return Calendar.FRIDAY;
41
+ if (day.startsWith('sa') || day === 'sabato') return Calendar.SATURDAY;
42
+ throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
43
+ }
44
+
45
+ // Java: DateCheckFilter#getMonth(String)
46
+ getMonth(monthStr) {
47
+ const mon = toLowerCase(monthStr);
48
+ if (mon.startsWith('gen')) return 1;
49
+ if (mon.startsWith('feb')) return 2;
50
+ if (mon.startsWith('mar')) return 3;
51
+ if (mon.startsWith('apr')) return 4;
52
+ if (mon.startsWith('mag')) return 5;
53
+ if (mon.startsWith('giu')) return 6;
54
+ if (mon.startsWith('lug')) return 7;
55
+ if (mon.startsWith('ago')) return 8;
56
+ if (mon.startsWith('set')) return 9;
57
+ if (mon.startsWith('ott')) return 10;
58
+ if (mon.startsWith('nov')) return 11;
59
+ if (mon.startsWith('dic')) return 12;
60
+ throw new RuntimeException("Could not find month '" + monthStr + "'");
61
+ }
62
+ }
63
+
64
+ registerClass(DateCheckFilter.FQCN, DateCheckFilter);
@@ -0,0 +1,37 @@
1
+ // Java: org.languagetool.rules.it.ItalianWordRepeatRule
2
+ import { WordRepeatRule } from '@valueerror/ltjs-core/src/core/rules/WordRepeatRule.js';
3
+ import { registerComponent } from '@valueerror/ltjs-core/src/core/language/components.js';
4
+
5
+ // Java: ItalianWordRepeatRule
6
+ export class ItalianWordRepeatRule extends WordRepeatRule {
7
+ static FQCN = 'org.languagetool.rules.it.ItalianWordRepeatRule';
8
+
9
+ // Java: ItalianWordRepeatRule(ResourceBundle,Language)
10
+ constructor(messages, language) {
11
+ super(messages, language);
12
+ }
13
+
14
+ // Java: ItalianWordRepeatRule#getId()
15
+ getId() {
16
+ return 'ITALIAN_WORD_REPEAT_RULE';
17
+ }
18
+
19
+ // Java: ItalianWordRepeatRule#ignore(AnalyzedTokenReadings[],int)
20
+ ignore(tokens, position) {
21
+ if (this.wordRepetitionOf('così', tokens, position)) {
22
+ return true; // "Mi è sembrato così così."
23
+ }
24
+ if (this.wordRepetitionOf('passo', tokens, position)) {
25
+ return true; // "che passo passo vanno verso la rovina"
26
+ }
27
+ if (this.wordRepetitionOf('piano', tokens, position)) {
28
+ return true; // "Piano, piano, signor podestà."
29
+ }
30
+ if (this.wordRepetitionOf('via', tokens, position)) {
31
+ return true; // "Il lessico si andava via via modificando."
32
+ }
33
+ return super.ignore(tokens, position);
34
+ }
35
+ }
36
+
37
+ registerComponent(ItalianWordRepeatRule.FQCN, (...args) => new ItalianWordRepeatRule(...args));
@@ -0,0 +1,48 @@
1
+ // Java: org.languagetool.rules.it.MorfologikItalianSpellerRule
2
+ import { MorfologikSpellerRule } from '@valueerror/ltjs-core/src/core/rules/spelling/morfologik/MorfologikSpellerRule.js';
3
+ import { registerComponent } from '@valueerror/ltjs-core/src/core/language/components.js';
4
+ import { isCapitalizedWord } from '@valueerror/ltjs-core/src/core/text/StringTools.js';
5
+ import { toLowerCase } from '@valueerror/ltjs-core/src/lib/java/strings.js';
6
+
7
+ const RESOURCE_FILENAME = '/it/hunspell/it_IT.dict';
8
+
9
+ // Java: MorfologikItalianSpellerRule
10
+ export class MorfologikItalianSpellerRule extends MorfologikSpellerRule {
11
+ static FQCN = 'org.languagetool.rules.it.MorfologikItalianSpellerRule';
12
+
13
+ // Java: MorfologikItalianSpellerRule(ResourceBundle,Language,UserConfig,List)
14
+ constructor(messages, language, userConfig, altLanguages) {
15
+ super(messages, language, userConfig, altLanguages);
16
+ }
17
+
18
+ // Java: MorfologikItalianSpellerRule#getFileName()
19
+ getFileName() {
20
+ return RESOURCE_FILENAME;
21
+ }
22
+
23
+ // Java: MorfologikItalianSpellerRule#getId()
24
+ getId() {
25
+ return 'MORFOLOGIK_RULE_IT_IT';
26
+ }
27
+
28
+ // Java: MorfologikItalianSpellerRule#orderSuggestions(List,String)
29
+ orderSuggestions(suggestions, word) {
30
+ const newSuggestions = [];
31
+ const originalSuggestionsStr = [];
32
+ for (const suggestion of suggestions) {
33
+ originalSuggestionsStr.push(suggestion.getReplacement());
34
+ }
35
+ for (const suggestion of suggestions) {
36
+ const suggestionStr = suggestion.getReplacement();
37
+ // original word is not capitalized, suggestion is capitalized, and lowercase suggestion also exists
38
+ if (!isCapitalizedWord(word) && isCapitalizedWord(suggestionStr)
39
+ && originalSuggestionsStr.includes(toLowerCase(suggestionStr))) {
40
+ continue;
41
+ }
42
+ newSuggestions.push(suggestion);
43
+ }
44
+ return newSuggestions;
45
+ }
46
+ }
47
+
48
+ registerComponent(MorfologikItalianSpellerRule.FQCN, (...args) => new MorfologikItalianSpellerRule(...args));
@@ -0,0 +1,20 @@
1
+ // Java: org.languagetool.synthesis.it.ItalianSynthesizer
2
+ import { registerComponent, sharedComponent } from '@valueerror/ltjs-core/src/core/language/components.js';
3
+ import { BaseSynthesizer } from '@valueerror/ltjs-core/src/core/tagging/synthesis/BaseSynthesizer.js';
4
+
5
+ // Java: ItalianSynthesizer
6
+ export class ItalianSynthesizer extends BaseSynthesizer {
7
+ static FQCN = 'org.languagetool.synthesis.it.ItalianSynthesizer';
8
+
9
+ // Java: ItalianSynthesizer#INSTANCE
10
+ static get INSTANCE() {
11
+ return sharedComponent(ItalianSynthesizer.FQCN);
12
+ }
13
+
14
+ // Java: ItalianSynthesizer#ItalianSynthesizer() (the deprecated (Language) constructor delegates here)
15
+ constructor() {
16
+ super(null, '/it/italian_synth.dict', '/it/italian_tags.txt', 'it');
17
+ }
18
+ }
19
+
20
+ registerComponent(ItalianSynthesizer.FQCN, () => new ItalianSynthesizer());
@@ -0,0 +1,23 @@
1
+ // Java: org.languagetool.tagging.disambiguation.rules.it.ItalianRuleDisambiguator
2
+ import { registerComponent } from '@valueerror/ltjs-core/src/core/language/components.js';
3
+ import { AbstractDisambiguator } from '@valueerror/ltjs-core/src/core/tagging/disambiguation/AbstractDisambiguator.js';
4
+ import { XmlRuleDisambiguator } from '@valueerror/ltjs-core/src/core/disambiguation/XmlRuleDisambiguator.js';
5
+ import { Italian } from '../language/Italian.js';
6
+
7
+ // Java: ItalianRuleDisambiguator
8
+ export class ItalianRuleDisambiguator extends AbstractDisambiguator {
9
+ static FQCN = 'org.languagetool.tagging.disambiguation.rules.it.ItalianRuleDisambiguator';
10
+
11
+ // Java: ItalianRuleDisambiguator#disambiguator (field initialiser: a second Italian instance)
12
+ constructor() {
13
+ super();
14
+ this.disambiguator = new XmlRuleDisambiguator(new Italian());
15
+ }
16
+
17
+ // Java: ItalianRuleDisambiguator#disambiguate(AnalyzedSentence)
18
+ disambiguate(input, checkCanceled = null) {
19
+ return this.disambiguator.disambiguate(input, checkCanceled);
20
+ }
21
+ }
22
+
23
+ registerComponent(ItalianRuleDisambiguator.FQCN, () => new ItalianRuleDisambiguator());
@@ -0,0 +1,16 @@
1
+ // Java: org.languagetool.tagging.it.ItalianTagger
2
+ import { Locale } from '@valueerror/ltjs-core/src/lib/java/Locale.js';
3
+ import { BaseTagger } from '@valueerror/ltjs-core/src/core/tagging/BaseTagger.js';
4
+ import { registerComponent } from '@valueerror/ltjs-core/src/core/language/components.js';
5
+
6
+ // Java: ItalianTagger
7
+ export class ItalianTagger extends BaseTagger {
8
+ static FQCN = 'org.languagetool.tagging.it.ItalianTagger';
9
+
10
+ // Java: ItalianTagger#ItalianTagger()
11
+ constructor() {
12
+ super('/it/italian.dict', Locale.ITALIAN);
13
+ }
14
+ }
15
+
16
+ registerComponent(ItalianTagger.FQCN, () => new ItalianTagger());