natural 7.1.0 → 8.0.1

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.
@@ -1,140 +0,0 @@
1
- /*
2
- Copyright (c) 2020, 2022 Hugo W.L. ter Doest
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- {
24
- const knownAbbreviations = require("../util/abbreviations_en").knownAbbreviations
25
- }
26
-
27
- s
28
- = sentences: (Sentences Whitespace / QuotedSentences Whitespace)+ {
29
- let result = []
30
- sentences.forEach(sent0 => {
31
- sent0[0].forEach(sent1 => {
32
- result.push(sent1)
33
- })
34
- })
35
- return result
36
- }
37
-
38
- Sentences
39
- = sentences: (Sentence Whitespace) + {
40
- //return sentences
41
- return(
42
- sentences.map(sent => {
43
- //if (sent[1]) {
44
- sent[0].push(sent[1])
45
- //}
46
- return sent[0].reduce((accu, str) => accu + str).trim()
47
- })
48
- )
49
- }
50
-
51
- QuotedSentences
52
- = open: OpenSymbol sentences: (Sentence Whitespace) + close: CloseSymbol? {
53
- //return sentences
54
- let result = sentences.map(sent => {
55
- //if (sent[1]) {
56
- sent[0].push(sent[1])
57
- //}
58
- return sent[0].reduce((accu, str) => accu + str).trim()
59
- })
60
- result.unshift(open)
61
- if (close) {
62
- result.push(close)
63
- }
64
- return result
65
- }
66
-
67
- Sentence
68
- = seqs: (TokenSeq / QuotedTokenSeq)+ end: EndOfSentence {
69
- let res = seqs.reduce((accu, seq) => accu.concat(seq))
70
- res.push(end)
71
- return res
72
- }
73
-
74
- TokenSeq
75
- = tokens: (Token Whitespace)+ {
76
- let result = tokens.map(pair => pair[0] + pair[1])
77
- return result
78
- }
79
-
80
- QuotedTokenSeq
81
- = open: OpenSymbol tokens: (Token Whitespace)+ end: EndOfSentence close: CloseSymbol {
82
- let result = tokens.map(pair => pair[0] + pair[1])
83
- result.unshift(open)
84
- result.push(end)
85
- result.push(close)
86
- return result
87
- }
88
-
89
- EndOfSentence
90
- = [ \t\n\r.?!]* {
91
- return text()
92
- }
93
-
94
- Whitespace
95
- = [ \t\n\r]* {
96
- return text()
97
- }
98
-
99
- Token
100
- = t: (URI / Email / Number / Abbreviation / Word) {
101
- return t
102
- }
103
-
104
- // An abbreviation may contain periods
105
- Abbreviation
106
- = word: [^ \t\n\r!?\(\[\}\"\`\)\]\}\"\`0-9\@]+ & {
107
- const tmp = word.reduce((accu, elt) => accu + elt)
108
- return knownAbbreviations.indexOf(tmp) > -1} {
109
- return text()
110
- }
111
-
112
- Word
113
- = [^ \t\n\r!?\.\(\[\}\)\]\}\`\"0-9\@]+ {
114
- return text()
115
- }
116
-
117
- Number
118
- = [0-9]+ (.[0-9]+)? CloseSymbol ? {
119
- return text()
120
- }
121
-
122
- Email
123
- = [a-z]+[@][a-z]+[.][a-z]+ {
124
- return text()
125
- }
126
-
127
- URI
128
- = ("http://" / "https://")? [a-z0-9]+[.]([a-z0-9]+[.])?[a-z0-9]+ ([a-z0-9]+[\/])* {
129
- return text()
130
- }
131
-
132
- OpenSymbol
133
- = [\(\[\{\"\'\`\‘] {
134
- return text()
135
- }
136
-
137
- CloseSymbol
138
- = [\)\]\}\"\'\`\’] {
139
- return text()
140
- }