skrutable 1.2.1__py3-none-any.whl

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.
skrutable/config.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "default_scheme_in" : "IAST",
3
+ "default_scheme_out" : "IAST",
4
+ "avoid_virAma_indic_scripts" : true,
5
+ "avoid_virAma_all_scripts" : false,
6
+ "scansion_syllable_separator" : " ",
7
+ "additional_pAda_separators" : ["\t", ";", ",", " / ", " | ", " । "],
8
+ "default_resplit_option" : "resplit_lite",
9
+ "default_resplit_keep_midpoint" : false,
10
+ "disable_non_trizwuB_upajAti" : true,
11
+ "meter_scores" : {
12
+ "max score" : 9,
13
+ "anuṣṭubh, full, both halves perfect)" : 9,
14
+ "anuṣṭubh, full, one half perfect, one imperfect)" : 7,
15
+ "anuṣṭubh, half, single half perfect)" : 9,
16
+ "samavṛtta, perfect" : 9,
17
+ "samavṛtta, imperfect (3)" : 6,
18
+ "samavṛtta, imperfect (2)" : 5,
19
+ "ardhasamavṛtta, perfect" : 8,
20
+ "ardhasamavṛtta, perfect, unknown" : 6,
21
+ "viṣamavṛtta, perfect" : 9,
22
+ "upajāti, perfect" : 7,
23
+ "upajāti, imperfect" : 6,
24
+ "upajāti, non-triṣṭubh, perfect" : 5,
25
+ "upajāti, triṣṭubh-jagatī-saṃkara, perfect" : 4,
26
+ "upajāti, non-triṣṭubh, imperfect" : 3,
27
+ "jāti, perfect" : 8,
28
+ "jāti, imperfect" : 3,
29
+ "none found" : 1
30
+ },
31
+ "preserve_punc_default" : true
32
+ }
skrutable/config.py ADDED
@@ -0,0 +1,9 @@
1
+ import os.path
2
+ import json
3
+
4
+ def load_config_dict_from_json_file():
5
+ abs_dir = os.path.split(os.path.abspath(__file__))[0]
6
+ settings_file_path = os.path.join(abs_dir, 'config.json')
7
+ config_data = open(settings_file_path,'r').read()
8
+ config = json.loads(config_data)
9
+ return config
skrutable/manual.md ADDED
@@ -0,0 +1,281 @@
1
+ # about
2
+
3
+ `skrutable` is a toolkit and online workbench providing
4
+ transliteration, scansion, and meter identification for Sanskrit text,
5
+ as well access to powerful sandhi and compound splitting.
6
+
7
+ For more context on the project, see [skrutable.info/about](https://www.skrutable.info/about)
8
+
9
+
10
+ # how to use
11
+
12
+ The online web app at [skrutable.info/](https://www.skrutable.info/)
13
+ provides easy access to both casual one-off and also whole-file processing.
14
+
15
+ ![screenshot](img/web_app.png)
16
+
17
+ See [skrutable.info/tutorial](https://www.skrutable.info/tutorial) for more instructions.
18
+
19
+ For Python programmers, it's also possible to import and use `skrutable` as a library.
20
+ Just `pip install skrutable` and you're ready to start.
21
+ See [below](#using-the-code) for more info.
22
+
23
+ Programmers in any language also have the option to query API endpoints.
24
+ See [below](#using-the-api) for more info on that.
25
+
26
+
27
+ # transliteration schemes
28
+
29
+ Sanskrit can be written in many ways. The schemes featured in `skrutable` are:
30
+
31
+ <table>
32
+ <thead>
33
+ <tr>
34
+ <th>Scheme Type</th>
35
+ <th>Scheme Abbreviation</th>
36
+ <th>Scheme Full Name</th>
37
+ <th>Example</th>
38
+ </tr>
39
+ </thead>
40
+ <tbody>
41
+ <tr>
42
+ <td rowspan=6>Roman</td>
43
+ <td>IAST</td>
44
+ <td>International Alphabet of Sanskrit Transliteration</td>
45
+ <td>saṃskṛtaṃ paṭhāmaḥ</td>
46
+ </tr>
47
+ <tr>
48
+ <td>HK</td>
49
+ <td>Harvard-Kyoto</td>
50
+ <td>saMskRtaM paThAmaH</td>
51
+ </tr>
52
+ <tr>
53
+ <td>SLP</td>
54
+ <td>Sanskrit Library Protocol 1</td>
55
+ <td>saMskftaM paWAmaH</td>
56
+ </tr>
57
+ <tr>
58
+ <td>ITRANS</td>
59
+ <td>Indian Languages Transliteration</td>
60
+ <td>sa.mskRita.m paThaama.h</td>
61
+ </tr>
62
+ <tr>
63
+ <td>VH</td>
64
+ <td>Velthuis</td>
65
+ <td>sa.msk.rta.m pa.Taama.h</td>
66
+ </tr>
67
+ <tr>
68
+ <td>WX</td>
69
+ <td>Scheme developed at IIT Kanpur</td>
70
+ <td>saMskqwaM paTAmaH</td>
71
+ </tr>
72
+ <tr>
73
+ <td rowspan=3>Indic</td>
74
+ <td>DEV</td>
75
+ <td>Devanagari Unicode</td>
76
+ <td>संस्कृतं पठामः</td>
77
+ </tr>
78
+ <tr>
79
+ <td>BENGALI</td>
80
+ <td>Bengali Unicode</td>
81
+ <td>সংস্কৃতং পঠামঃ</td>
82
+ </tr>
83
+ <tr>
84
+ <td>GUJARATI</td>
85
+ <td>Gujarati Unicode</td>
86
+ <td>સંસ્કૃતં પઠામઃ</td>
87
+ </tr>
88
+ </tbody>
89
+ </table>
90
+
91
+ There is also a very lossy “IASTreduced” (e.g., “samskrtam pathamah”) output option which I find sometimes comes in handy. Additional academic schemes not currently featured include CSX (Classical Sanskrit eXtended, e.g. “saüskçtaü paòâmaþ”), REE (by Ronald E. Emmerick, e.g. “saæsk­taæ paèÃma÷”), and the scheme internal to the [DCS](http://www.sanskrit-linguistics.org/dcs/index.php) (by Oliver Hellwig, e.g. “saºskŸtaº paÅåmaµ”).
92
+
93
+ More schemes for writing Sanskrit, especially those corresponding to additional Indic scripts, can easily be added to `skrutable` by modifying the code in `phonemes.py` and `scheme_maps.py`. I'm happy to help with this to some extent. Alternatively, for other tools more focused on wider character support, including for other South Asian languages, see [related projects](#related-projects) below.
94
+
95
+ Note that I use “encoding” here in the sense of UTF-8 (most often as in over and above ASCII) and “script” in the sense of a distinct character set like either the Roman or Devanagari alphabets (latter actually an abugida), and so I don't use either “Roman” or “Unicode” to refer to any of the individual schemes. For more thoughts on such terminology, see [here](http://indology.info/email/members/wujastyk/) and [here](http://sanskritlibrary.org/Sanskrit/pub/lies_sl.pdf).
96
+
97
+
98
+ # scansion and meter identification
99
+
100
+ For the concepts and traditional conventions in Sanskrit prosody which `skrutable`'s meter functionality is based on, see above all the appendix of V.S. Apte's *Practical Sanskrit-English dictionary*, 1890, pp. 1179ff. ([on Archive](https://archive.org/details/ldpd_7285627_000/page/n1195/mode/2up))
101
+
102
+ The most important terms in short:
103
+ * *laghu* (l) / *guru* (g): metrically light / heavy syllable
104
+ * mora: value of 1 for each light syllable and 2 for each heavy syllable
105
+ * *gaṇa*: [traditional abbreviation](https://en.wikipedia.org/wiki/Sanskrit_prosody#Ga%E1%B9%87a) — ya ma ta ra ja bha na sa (la ga) — for each [trisyllable (or monosyllable) group](https://en.wikipedia.org/wiki/Foot_(prosody))
106
+ * *anuṣṭubh* (also *śloka*): a verse type consisting of 8 syllables (roughly: *akṣaras*) per quarter (or *pāda*) in a partly constrained, partly fluid *laghu-guru* pattern
107
+ * *samavṛtta*: a verse type containing four quarters with the same number of syllables in each and generally a rigid pattern of *laghu*s and *guru*s
108
+ * *jāti*: a verse type containing four quarters with set patterns of total moraic length
109
+
110
+
111
+ # related projects
112
+
113
+ There are numerous related projects which users may find preferable to `skrutable` in certain respects (e.g., more script support, different opinions on edge cases, etc.) Here are my recommended highlights.
114
+
115
+ | Scheme Detection | Transliteration | Scansion & Meter Identification | Main Author |
116
+ | ---| ---|------------------------------------------------------------------------------------------------| ---|
117
+ | ([“detect.py” module](https://github.com/sanskrit/detect.py)) | **[Sanscript](http://learnsanskrit.org/tools/sanscript)** (also via PyPi [here](https://github.com/sanskrit-coders/indic_transliteration)) | (n/a) | Arun K. Prasad (et al.?) |
118
+ | (n/a) | **[Aksharamukha](http://aksharamukha.appspot.com/converter)** | (n/a) | Vinodh Rajan |
119
+ | (n/a) | **[Transliteration Tool](https://www.ashtangayoga.info/philosophy/sanskrit-and-devanagari/transliteration-tool/)** | (n/a) | AshtangaYoga.info |
120
+ | (n/a) | **[Sanscription](http://www.tyfen.com/sanscription/)** | (n/a) | Marc Tiefenauer |
121
+ | ([“detect.py” module](https://github.com/shreevatsa/sanskrit/blob/master/transliteration/detect.py)) | ([“transliteration” subpackage](https://github.com/shreevatsa/sanskrit/tree/master/transliteration)) | **[Metre Identifier](http://sanskritmetres.appspot.com/)** | Shreevatsa Rajagopalan |
122
+ | (n/a) | (n/a) | **[Meter Identifying Tool](http://sanskritlibrary.org:8080/MeterIdentification/)** | Keshav Melnad |
123
+ | (n/a) | (n/a) | **[Chandojñānam](https://sanskrit.iitk.ac.in/jnanasangraha/chanda/)** | Hrishikesh Terdalkar |
124
+
125
+
126
+
127
+ # encoding normalization
128
+
129
+ Some schemes have internal options. For example, at the level of encoding, IAST is sometimes represented in UTF-8 with combining diacritics, sometimes with precomposed combinations. Alternatively, at the level of the scheme itself, ITRANS writes vocalic r (ṛ, ऋ) as 'Ri', 'RRi', or 'R^i. Because `skrutable` transliterates by way of SLP, and because it must output a single option, you can use round-trip transliteration (e.g., IAST-IAST) to normalize such variation. For example:
130
+
131
+ ~~~
132
+ "rāmaḥ" == 'r' + 'a' + '¯' (U+0304) + 'm' + 'a' + 'h' + '.' (U+0323)
133
+ >>
134
+ "rāmaḥ" == 'r' + 'ā' (U+0101) + 'm' + 'a' + 'ḥ' (U+1E25)
135
+ ~~~
136
+
137
+ That is, `skrutable` currently favors precomposed characters for IAST. In the code, these and other scheme-internal defaults can be inspected and changed in `scheme_maps.py`.
138
+
139
+
140
+ # virāma avoidance
141
+
142
+ For the purpose of printing Indic scripts, it's often aesthetically (if not always scientifically) preferable to remove certain inter-word spaces and their corresponding virāmas, and to instead use ligatures. For example:
143
+
144
+ ~~~
145
+ asty eva >> ( अस्त्य् एव ) >> अस्त्येव
146
+ ~~~
147
+
148
+ This is the default behavior for transliterating to Indic scripts in `skrutable`. In the code, the regular expressions governing this can be found in `virAma_avoidance.py`, and the overall setting can be toggled in `config.py`.
149
+
150
+
151
+ # sandhi and compound splitting
152
+
153
+ For splitting Sanskrit text into its individual words, both breaking compounds and dissolving sandhi, the powerful neural-network tool of Hellwig and Nehrdich, [Sanskrit Sandhi and Compound Splitter](https://github.com/OliverHellwig/sanskrit/tree/master/papers/2018emnlp), has been producing good and usable results since its 2018 release, even without re-training the model (examples: [here](https://github.com/tylergneill/pramana-nlp/tree/master/3_text_doc_and_word_segmented) and [here](https://github.com/sebastian-nehrdich/gretil-quotations)). By itself, however, it is not very accessible to potential users, being accessed via the command-line only and requiring setup of the somewhat outdated `Python 3.5` and `TensorFlow 1.x`.
154
+
155
+ To remedy this, `skrutable` provides a wrapper, accessible through its online interface and the importable library, for easily applying the pre-trained model while also (bonus!) preserving original sentence length and punctuation. This wrapper actually communicates with a separate online server ([splitter_server](https://splitter-server-tylergneill.pythonanywhere.com/)), so you'll need a working internet connection for this functionality.
156
+ (A previous, offline solution for incorporating the splitter involved
157
+ requiring the user to set up `TensorFlow 1.x` on `Python 3.5`
158
+ and to bridge different versions of Python with inelegant path hacks.
159
+ Remnants of this still remain in the codebase and can be made to work if needed
160
+ but are totally inactive at present.)
161
+
162
+
163
+ # using the code
164
+
165
+ ## installation
166
+
167
+ 1. Have Python 3 installed (`Homebrew` and Python 3.8+ recommended)
168
+
169
+ 2. Run `pip3 install skrutable` ([latest version on PyPi](https://pypi.org/project/skrutable/))
170
+
171
+ ## objects
172
+
173
+ From each respective Python module (`transliteration.py`, `scansion.py`, `meter_identification.py`, `splitter.wrapper.py`), import the respective object constructor (`Transliterator`, `Scanner`, `MeterIdentifier`, `Splitter`), instantiate the object, and call its primary methods (`transliterate()`, `scan()`, `identify_meter()`, `split()`). Transliteration and sandhi/compound splitting both return strings, whereas scansion and meter identification return `Scansion.Verse` objects, which themselves contain (among other things) a `meter_label` string attribute and a `summarize()` method that returns a string.
174
+
175
+ The following are the important function parameters:
176
+
177
+ * transliteration: `from_scheme` and `to_scheme` (`IAST`, `HK`, `SLP`, `ITRANS`, `VH`, `WX`, `IASTreduced`, `DEV`, `BENGALI`, `GUJARATI`),
178
+ * scansion: `show_weights`, `show_morae`, `show_gaRas`, `show_alignment` (`True`, `False`)
179
+ * meter identification: `resplit_option` (`none`, `resplit_lite`, `resplit_max`), `keep_mid` (`True`, `False`)
180
+ * sandhi/compound splitting: `prsrv_punc` (`True`, `False`)
181
+
182
+ Examples:
183
+
184
+ ~~~
185
+ input_string = "tava karakamalasthāṃ sphāṭikīmakṣamālāṃ , nakhakiraṇavibhinnāṃ dāḍimībījabuddhyā | pratikalamanukarṣanyena kīro niṣiddhaḥ , sa bhavatu mama bhūtyai vāṇi te mandahāsaḥ ||"
186
+ ~~~
187
+
188
+ 1. `skrutable.transliteration`, `transliteration.Transliterator`, `Transliterator.transliterate()`
189
+ ~~~
190
+ from skrutable.transliteration import Transliterator
191
+ T = Transliterator(to_scheme='DEV') # using built-in default from_scheme IAST but passing in a default to_scheme
192
+ string_result_1 = T.transliterate( input_string ) # from_scheme=IAST, to_scheme=DEV
193
+ string_result_2 = T.transliterate( input_string, to_scheme='BENGALI') # overriding to_scheme
194
+ ~~~
195
+
196
+ 2. `skrutable.scansion`, `scansion.Scanner`, `Scanner.scan()`
197
+ ~~~
198
+ from skrutable.scansion import Scanner
199
+ S = Scanner() # has default IAST from_scheme and "show" options True
200
+ Verse_result_1 = S.scan( input_string ) # using all defaults
201
+ print( Verse_result_1.summarize(show_label=False) ) # not showing empty label makes more sense
202
+ print( Verse_result_1.summarize(show_alignment=False, show_label=False) ) # can also toggle other things
203
+ Verse_result_2 = S.scan( input_string, from_scheme='DEV') # can also specify different input scheme here if needed
204
+ ~~~
205
+
206
+ 3. `skrutable.meter_identification`, `meter_identification.MeterIdentifier`, `MeterIdentifier.identify_meter()`
207
+ ~~~
208
+ from skrutable.meter_identification import MeterIdentifier
209
+ MI = MeterIdentifier()
210
+ Verse_result_1 = MI.identify_meter(input_string) # default from_scheme and resplit_option
211
+ print( Verse_result_1.meter_label )
212
+ print( Verse_result_1.summarize() )
213
+ Verse_result_2 = MI.identify_meter(input_string, resplit_option='none') # can change way pāda resplitting is done
214
+ Verse_result_3 = MI.identify_meter(input_string, from_scheme='DEV', resplit_option='resplit_lite') # scheme options possible here too
215
+ ~~~
216
+
217
+ 4. `skrutable.splitter.wrapper`, `splitter.wrapper.Splitter`, `Splitter.split()`
218
+ ~~~
219
+ from skrutable.splitter.wrapper import Splitter
220
+ Spl = Splitter()
221
+ # this needs an internet connection to connect to the API server
222
+ string_result_1 = Spl.split( input_string ) # default prsrv_punc
223
+ string_result_2 = Spl.split( input_string, prsrv_punc=False ) # discard punctuation
224
+ ~~~
225
+
226
+ More examples of how to use the library can be found in the repo's `tests` folder (for use with `pytest`) and in the `jupyter_notebooks` folder.
227
+
228
+
229
+ ## using the API
230
+
231
+ As an alternative to using the Python library,
232
+ you can also access the same four functionalities described above
233
+ by querying the `skrutable` server over the internet.
234
+ This Application Programming Interface (API)
235
+ has four endpoints, one for each functionality,
236
+ and each with the same set of options that the library offers.
237
+ You can use cURL, a Python library, or numerous other methods for making these queries.
238
+ Latency for small queries should be under 2 seconds
239
+ (first attempts may be slow; the server occasionally needs to be woken up).
240
+
241
+ See [skrutable.info/api](https://www.skrutable.info/api)
242
+ for more specific instructions.
243
+
244
+ ## using as command-line script
245
+
246
+ Another way to run the code is the little command-line script `skrutable_one.py`.
247
+ This also requires installing the Python library but avoids the need to write any Python code,
248
+ if one is more comfortable with Bash, for example. The easiest way to use it is to make a copy of `skrutable_one.py` and put it the same location as your desired input file. Then just run `python skrutable_one.py` at the command line with the proper arguments. Examples:
249
+
250
+ 1. transliterate to Bengali script:
251
+ ~~~
252
+ python skrutable_one.py --transliterate FILENAME.txt from_scheme=IAST to_scheme=BENGALI
253
+ ~~~
254
+
255
+ 2. identify meter for a single verse:
256
+ ~~~
257
+ python skrutable_one.py --identify_meter FILENAME.txt resplit_option=none from_scheme=IAST
258
+ ~~~
259
+
260
+ 3. identify meter for a whole file (one verse per line):
261
+ ~~~
262
+ python skrutable_one.py --identify_meter --whole_file FILENAME.txt resplit_option=resplit_lite from_scheme=IAST
263
+ ~~~
264
+
265
+
266
+ ## using the web app locally
267
+
268
+ There's yet another way of using `skrutable` that might come in handy for researchers doing more data-heavy processing, and that is to install and run the front-end web app locally on your own machine. In this way, you don't have to send information over the internet, so overall processing should be faster. To set this up, you'll need to also download the [separate front-end repo](https://github.com/tylergneill/skrutable_front_end). To support this, if you don't already have it, `pip install flask`. Then to start the local server, simply navigate into the folder with `flask_app.py` on the command line and run `bash launch.sh` (or `bash launch_https.sh` to be able to access the splitter server). You can then access `skrutable` in your browser at `http://127.0.0.1:5000` (or `https://127.0.0.1:5000`). The front end locally imports the `skrutable` package as its back end, so don't forget to install that first.
269
+
270
+
271
+ See [here](https://flask.palletsprojects.com/en/1.1.x/quickstart/)
272
+ for more info on the Flask framework, if you're curious.
273
+
274
+
275
+ # feedback
276
+
277
+ Whatever's on your mind, get in touch!
278
+ My name is Tyler
279
+ ([Academia](https://uni-leipzig1.academia.edu/TylerNeill),
280
+ [LinkedIn](https://www.linkedin.com/in/tyler-g-neill/))
281
+ and my Gmail is tyler.g.neill.