项目作者: hou2zi0

项目描述 :
Small Python wrapper class for the CAB webservice.
高级语言: Python
项目地址: git://github.com/hou2zi0/python-wrapper-cab-webservice.git
创建时间: 2019-10-13T12:56:31Z
项目社区:https://github.com/hou2zi0/python-wrapper-cab-webservice

开源协议:MIT License

下载


python-wrapper-cab-webservice

Small Python wrapper class for the CAB-webservice.

This class provides a simple interface to interact with B. Jurish’s CAB-webservice from within Python.

CAB-webservice

The CAB-webservice was created by B. Jurish. For more information about the CAB-webservice please see:

Jurish, B. Finite-state Canonicalization Techniques for Historical German. PhD thesis, Universität Potsdam, 2012 (defended 2011). URN urn:nbn:de:kobv:517-opus-55789.

How to use the class

Download the CabWebserviceWrapper.py file. Put the file into the same folder where your other Python files or jupyter notebooks are located.

  1. # Import the class
  2. from CabWebserviceWrapper import CabWrapper
  3. # Instantiate the class
  4. CAB = CabWrapper()
  5. # Set the return format: json, text, csv, raw, ltwxml, dataframe
  6. CAB.format = 'json'
  7. # Set the outputs you want (word, lemma, a/o pos), just concatenate them with pluses
  8. CAB.output = 'word+lemma+pos'
  9. # Query a text
  10. CAB.getText('Jn jm war das Leben / vnd das Leben war das Liecht der Menschen / vnd das Liecht scheinet in der Finsternis / vnd die Finsternis habens nicht begriffen.')

The example text is taken from the English Wikipedia Early New High German (Gospel of John, 1:1–5).

The output and the return value should be as follows. Apart from json and dataframe the class may as well return other formats provided by the CAB-webservice e.g. csv (tabs), text (with vertical attributes), raw (just the normalized text), ltwxml (linguistic xml), list (just the normalized tokens):

JSON

  1. [
  2. {
  3. 'word':'In',
  4. 'lemma':'in',
  5. 'pos':'APPR'
  6. },
  7. {
  8. 'word':'ihm',
  9. 'lemma':'er',
  10. 'pos':'PPER'
  11. },
  12. {
  13. 'word':'war',
  14. 'lemma':'sein',
  15. 'pos':'VAFIN'
  16. },
  17. {
  18. 'word':'das',
  19. 'lemma':'d',
  20. 'pos':'ART'
  21. },
  22. {
  23. 'word':'Leben',
  24. 'lemma':'Leben',
  25. 'pos':'NN'
  26. },
  27. {
  28. 'word':'/',
  29. 'lemma':'/',
  30. 'pos':'$('
  31. },
  32. {
  33. 'word':'und',
  34. 'lemma':'und',
  35. 'pos':'KON'
  36. },
  37. {
  38. 'word':'das',
  39. 'lemma':'d',
  40. 'pos':'ART'
  41. },
  42. {
  43. 'word':'Leben',
  44. 'lemma':'Leben',
  45. 'pos':'NN'
  46. },
  47. {
  48. 'word':'war',
  49. 'lemma':'sein',
  50. 'pos':'VAFIN'
  51. },
  52. {
  53. 'word':'das',
  54. 'lemma':'d',
  55. 'pos':'ART'
  56. },
  57. {
  58. 'word':'Licht',
  59. 'lemma':'Licht',
  60. 'pos':'NN'
  61. },
  62. {
  63. 'word':'der',
  64. 'lemma':'d',
  65. 'pos':'ART'
  66. },
  67. {
  68. 'word':'Menschen',
  69. 'lemma':'Mensch',
  70. 'pos':'NN'
  71. },
  72. {
  73. 'word':'/',
  74. 'lemma':'/',
  75. 'pos':'$('
  76. },
  77. {
  78. 'word':'und',
  79. 'lemma':'und',
  80. 'pos':'KON'
  81. },
  82. {
  83. 'word':'das',
  84. 'lemma':'d',
  85. 'pos':'ART'
  86. },
  87. {
  88. 'word':'Licht',
  89. 'lemma':'Licht',
  90. 'pos':'NN'
  91. },
  92. {
  93. 'word':'scheinet',
  94. 'lemma':'scheinen',
  95. 'pos':'VVFIN'
  96. },
  97. {
  98. 'word':'in',
  99. 'lemma':'in',
  100. 'pos':'APPR'
  101. },
  102. {
  103. 'word':'der',
  104. 'lemma':'d',
  105. 'pos':'ART'
  106. },
  107. {
  108. 'word':'Finsternis',
  109. 'lemma':'Finsternis',
  110. 'pos':'NN'
  111. },
  112. {
  113. 'word':'/',
  114. 'lemma':'/',
  115. 'pos':'$('
  116. },
  117. {
  118. 'word':'und',
  119. 'lemma':'und',
  120. 'pos':'KON'
  121. },
  122. {
  123. 'word':'die',
  124. 'lemma':'d',
  125. 'pos':'ART'
  126. },
  127. {
  128. 'word':'Finsternis',
  129. 'lemma':'Finsternis',
  130. 'pos':'NN'
  131. },
  132. {
  133. 'word':'habens',
  134. 'lemma':'Habens',
  135. 'pos':'NE'
  136. },
  137. {
  138. 'word':'nicht',
  139. 'lemma':'nicht',
  140. 'pos':'PTKNEG'
  141. },
  142. {
  143. 'word':'begriffen',
  144. 'lemma':'begreifen',
  145. 'pos':'VVPP'
  146. },
  147. {
  148. 'word':'.',
  149. 'lemma':'.',
  150. 'pos':'$.'
  151. }
  152. ]

DataFrame

You may as well let the class return a dataframe:

  1. CAB = CabWrapper()
  2. # Set the return format: json, text, csv, raw, ltwxml, dataframe
  3. CAB.format = 'dataframe'
  4. # Set the outputs you want (word, lemma, a/o pos), just concatenate them with pluses
  5. CAB.output = 'word+lemma+pos'
  6. # Query a text
  7. CAB.getText('Jn jm war das Leben / vnd das Leben war das Liecht der Menschen / vnd das Liecht scheinet in der Finsternis / vnd die Finsternis habens nicht begriffen.')

The returned dataframe:

  1. word lemma pos
  2. 0 In in APPR
  3. 1 ihm er PPER
  4. 2 war sein VAFIN
  5. 3 das d ART
  6. 4 Leben Leben NN
  7. 5 / / $(
  8. 6 und und KON
  9. 7 das d ART
  10. 8 Leben Leben NN
  11. 9 war sein VAFIN
  12. 10 das d ART
  13. 11 Licht Licht NN
  14. 12 der d ART
  15. 13 Menschen Mensch NN
  16. 14 / / $(
  17. 15 und und KON
  18. 16 das d ART
  19. 17 Licht Licht NN
  20. 18 scheinet scheinen VVFIN
  21. 19 in in APPR
  22. 20 der d ART
  23. 21 Finsternis Finsternis NN
  24. 22 / / $(
  25. 23 und und KON
  26. 24 die d ART
  27. 25 Finsternis Finsternis NN
  28. 26 habens Habens NE
  29. 27 nicht nicht PTKNEG
  30. 28 begriffen begreifen VVPP
  31. 29 . . $.

CSV (Tabs)

  1. %% $s:lang=de
  2. Jn Jn In APPR in
  3. jm jm ihm PPER er
  4. war war war VAFIN sein
  5. das das das ART d
  6. Leben Leben Leben NN Leben
  7. / / / $( /
  8. vnd vnd und KON und
  9. das das das ART d
  10. Leben Leben Leben NN Leben
  11. war war war VAFIN sein
  12. das das das ART d
  13. Liecht Liecht Licht NN Licht
  14. der der der ART d
  15. Menschen Menschen Menschen NN Mensch
  16. / / / $( /
  17. vnd vnd und KON und
  18. das das das ART d
  19. Liecht Liecht Licht NN Licht
  20. scheinet scheinet scheinet VVFIN scheinen
  21. in in in APPR in
  22. der der der ART d
  23. Finsternis Finsternis Finsternis NN Finsternis
  24. / / / $( /
  25. vnd vnd und KON und
  26. die die die ART d
  27. Finsternis Finsternis Finsternis NN Finsternis
  28. habens habens habens NE Habens
  29. nicht nicht nicht PTKNEG nicht
  30. begriffen begriffen begriffen VVPP begreifen
  31. . . . $. .

Text (with Annotations)

  1. %% $s:lang=de
  2. Jn
  3. +[exlex] In
  4. +[errid] 68640
  5. +[xlit] l1=1 lx=1 l1s=Jn
  6. +[morph/safe] 0
  7. +[moot/word] In
  8. +[moot/tag] APPR
  9. +[moot/lemma] in
  10. jm
  11. +[exlex] ihm
  12. +[errid] 65879
  13. +[lang] de
  14. +[xlit] l1=1 lx=1 l1s=jm
  15. +[hasmorph] 1
  16. +[morph/safe] 1
  17. +[moot/word] ihm
  18. +[moot/tag] PPER
  19. +[moot/lemma] er
  20. war
  21. +[exlex] war
  22. +[errid] 49126
  23. +[lang] de
  24. +[xlit] l1=1 lx=1 l1s=war
  25. +[hasmorph] 1
  26. +[morph/safe] 1
  27. +[moot/word] war
  28. +[moot/tag] VAFIN
  29. +[moot/lemma] sein
  30. das
  31. +[exlex] das
  32. +[errid] 24980
  33. +[lang] de
  34. +[xlit] l1=1 lx=1 l1s=das
  35. +[hasmorph] 1
  36. +[morph/safe] 1
  37. +[moot/word] das
  38. +[moot/tag] ART
  39. +[moot/lemma] d
  40. Leben
  41. +[exlex] Leben
  42. +[errid] ec
  43. +[lang] de
  44. +[xlit] l1=1 lx=1 l1s=Leben
  45. +[hasmorph] 1
  46. +[morph/safe] 1
  47. +[moot/word] Leben
  48. +[moot/tag] NN
  49. +[moot/lemma] Leben
  50. /
  51. +[xlit] l1=1 lx=1 l1s=/
  52. +[morph/safe] 1
  53. +[moot/word] /
  54. +[moot/tag] $(
  55. +[moot/lemma] /
  56. vnd
  57. +[exlex] und
  58. +[errid] 9652
  59. +[lang] de
  60. +[xlit] l1=1 lx=1 l1s=vnd
  61. +[morph/safe] 0
  62. +[moot/word] und
  63. +[moot/tag] KON
  64. +[moot/lemma] und
  65. das
  66. +[exlex] das
  67. +[errid] 24980
  68. +[lang] de
  69. +[xlit] l1=1 lx=1 l1s=das
  70. +[hasmorph] 1
  71. +[morph/safe] 1
  72. +[moot/word] das
  73. +[moot/tag] ART
  74. +[moot/lemma] d
  75. Leben
  76. +[exlex] Leben
  77. +[errid] ec
  78. +[lang] de
  79. +[xlit] l1=1 lx=1 l1s=Leben
  80. +[hasmorph] 1
  81. +[morph/safe] 1
  82. +[moot/word] Leben
  83. +[moot/tag] NN
  84. +[moot/lemma] Leben
  85. war
  86. +[exlex] war
  87. +[errid] 49126
  88. +[lang] de
  89. +[xlit] l1=1 lx=1 l1s=war
  90. +[hasmorph] 1
  91. +[morph/safe] 1
  92. +[moot/word] war
  93. +[moot/tag] VAFIN
  94. +[moot/lemma] sein
  95. das
  96. +[exlex] das
  97. +[errid] 24980
  98. +[lang] de
  99. +[xlit] l1=1 lx=1 l1s=das
  100. +[hasmorph] 1
  101. +[morph/safe] 1
  102. +[moot/word] das
  103. +[moot/tag] ART
  104. +[moot/lemma] d
  105. Liecht
  106. +[exlex] Licht
  107. +[errid] 82068
  108. +[xlit] l1=1 lx=1 l1s=Liecht
  109. +[morph/safe] 0
  110. +[moot/word] Licht
  111. +[moot/tag] NN
  112. +[moot/lemma] Licht
  113. der
  114. +[exlex] der
  115. +[errid] 57133
  116. +[lang] de
  117. +[xlit] l1=1 lx=1 l1s=der
  118. +[hasmorph] 1
  119. +[morph/safe] 1
  120. +[moot/word] der
  121. +[moot/tag] ART
  122. +[moot/lemma] d
  123. Menschen
  124. +[exlex] Menschen
  125. +[errid] ec
  126. +[lang] de
  127. +[xlit] l1=1 lx=1 l1s=Menschen
  128. +[hasmorph] 1
  129. +[morph/safe] 1
  130. +[moot/word] Menschen
  131. +[moot/tag] NN
  132. +[moot/lemma] Mensch
  133. /
  134. +[xlit] l1=1 lx=1 l1s=/
  135. +[morph/safe] 1
  136. +[moot/word] /
  137. +[moot/tag] $(
  138. +[moot/lemma] /
  139. vnd
  140. +[exlex] und
  141. +[errid] 9652
  142. +[lang] de
  143. +[xlit] l1=1 lx=1 l1s=vnd
  144. +[morph/safe] 0
  145. +[moot/word] und
  146. +[moot/tag] KON
  147. +[moot/lemma] und
  148. das
  149. +[exlex] das
  150. +[errid] 24980
  151. +[lang] de
  152. +[xlit] l1=1 lx=1 l1s=das
  153. +[hasmorph] 1
  154. +[morph/safe] 1
  155. +[moot/word] das
  156. +[moot/tag] ART
  157. +[moot/lemma] d
  158. Liecht
  159. +[exlex] Licht
  160. +[errid] 82068
  161. +[xlit] l1=1 lx=1 l1s=Liecht
  162. +[morph/safe] 0
  163. +[moot/word] Licht
  164. +[moot/tag] NN
  165. +[moot/lemma] Licht
  166. scheinet
  167. +[lang] de
  168. +[xlit] l1=1 lx=1 l1s=scheinet
  169. +[hasmorph] 1
  170. +[morph/safe] 1
  171. +[moot/word] scheinet
  172. +[moot/tag] VVFIN
  173. +[moot/lemma] scheinen
  174. in
  175. +[exlex] in
  176. +[errid] ec
  177. +[lang] de
  178. +[xlit] l1=1 lx=1 l1s=in
  179. +[hasmorph] 1
  180. +[morph/safe] 1
  181. +[moot/word] in
  182. +[moot/tag] APPR
  183. +[moot/lemma] in
  184. der
  185. +[exlex] der
  186. +[errid] 57133
  187. +[lang] de
  188. +[xlit] l1=1 lx=1 l1s=der
  189. +[hasmorph] 1
  190. +[morph/safe] 1
  191. +[moot/word] der
  192. +[moot/tag] ART
  193. +[moot/lemma] d
  194. Finsternis
  195. +[exlex] Finsternis
  196. +[errid] ec
  197. +[lang] de
  198. +[xlit] l1=1 lx=1 l1s=Finsternis
  199. +[hasmorph] 1
  200. +[morph/safe] 1
  201. +[moot/word] Finsternis
  202. +[moot/tag] NN
  203. +[moot/lemma] Finsternis
  204. /
  205. +[xlit] l1=1 lx=1 l1s=/
  206. +[morph/safe] 1
  207. +[moot/word] /
  208. +[moot/tag] $(
  209. +[moot/lemma] /
  210. vnd
  211. +[exlex] und
  212. +[errid] 9652
  213. +[lang] de
  214. +[xlit] l1=1 lx=1 l1s=vnd
  215. +[morph/safe] 0
  216. +[moot/word] und
  217. +[moot/tag] KON
  218. +[moot/lemma] und
  219. die
  220. +[exlex] die
  221. +[errid] ec
  222. +[lang] de
  223. +[xlit] l1=1 lx=1 l1s=die
  224. +[hasmorph] 1
  225. +[morph/safe] 1
  226. +[moot/word] die
  227. +[moot/tag] ART
  228. +[moot/lemma] d
  229. Finsternis
  230. +[exlex] Finsternis
  231. +[errid] ec
  232. +[lang] de
  233. +[xlit] l1=1 lx=1 l1s=Finsternis
  234. +[hasmorph] 1
  235. +[morph/safe] 1
  236. +[moot/word] Finsternis
  237. +[moot/tag] NN
  238. +[moot/lemma] Finsternis
  239. habens
  240. +[lang] la
  241. +[xlit] l1=1 lx=1 l1s=habens
  242. +[morph/lat] [_FM][lat] <0>
  243. +[morph/safe] 1
  244. +[moot/word] habens
  245. +[moot/tag] NE
  246. +[moot/lemma] Habens
  247. nicht
  248. +[exlex] nicht
  249. +[errid] ec
  250. +[lang] de
  251. +[xlit] l1=1 lx=1 l1s=nicht
  252. +[hasmorph] 1
  253. +[morph/safe] 1
  254. +[moot/word] nicht
  255. +[moot/tag] PTKNEG
  256. +[moot/lemma] nicht
  257. begriffen
  258. +[exlex] begriffen
  259. +[errid] ec
  260. +[lang] de
  261. +[xlit] l1=1 lx=1 l1s=begriffen
  262. +[hasmorph] 1
  263. +[morph/safe] 1
  264. +[moot/word] begriffen
  265. +[moot/tag] VVPP
  266. +[moot/lemma] begreifen
  267. .
  268. +[exlex] .
  269. +[errid] ec
  270. +[xlit] l1=1 lx=1 l1s=.
  271. +[morph/safe] 1
  272. +[moot/word] .
  273. +[moot/tag] $.
  274. +[moot/lemma] .

Raw Text

  1. In ihm war das Leben / und das Leben war das Licht der Menschen / und das Licht scheinet in der Finsternis / und die Finsternis habens nicht begriffen .

ltwxml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <text>
  3. <s>
  4. <w lemma="in" pos="APPR" norm="In">Jn</w>
  5. <w lemma="er" pos="PPER" norm="ihm">jm</w>
  6. <w lemma="sein" pos="VAFIN" norm="war">war</w>
  7. <w lemma="d" pos="ART" norm="das">das</w>
  8. <w lemma="Leben" pos="NN" norm="Leben">Leben</w>
  9. <w lemma="/" pos="$(" norm="/">/</w>
  10. <w lemma="und" pos="KON" norm="und">vnd</w>
  11. <w lemma="d" pos="ART" norm="das">das</w>
  12. <w lemma="Leben" pos="NN" norm="Leben">Leben</w>
  13. <w lemma="sein" pos="VAFIN" norm="war">war</w>
  14. <w lemma="d" pos="ART" norm="das">das</w>
  15. <w lemma="Licht" pos="NN" norm="Licht">Liecht</w>
  16. <w lemma="d" pos="ART" norm="der">der</w>
  17. <w lemma="Mensch" pos="NN" norm="Menschen">Menschen</w>
  18. <w lemma="/" pos="$(" norm="/">/</w>
  19. <w lemma="und" pos="KON" norm="und">vnd</w>
  20. <w lemma="d" pos="ART" norm="das">das</w>
  21. <w lemma="Licht" pos="NN" norm="Licht">Liecht</w>
  22. <w lemma="scheinen" pos="VVFIN" norm="scheinet">scheinet</w>
  23. <w lemma="in" pos="APPR" norm="in">in</w>
  24. <w lemma="d" pos="ART" norm="der">der</w>
  25. <w lemma="Finsternis" pos="NN" norm="Finsternis">Finsternis</w>
  26. <w lemma="/" pos="$(" norm="/">/</w>
  27. <w lemma="und" pos="KON" norm="und">vnd</w>
  28. <w lemma="d" pos="ART" norm="die">die</w>
  29. <w lemma="Finsternis" pos="NN" norm="Finsternis">Finsternis</w>
  30. <w lemma="Habens" pos="NE" norm="habens">habens</w>
  31. <w lemma="nicht" pos="PTKNEG" norm="nicht">nicht</w>
  32. <w lemma="begreifen" pos="VVPP" norm="begriffen">begriffen</w>
  33. <w lemma="." pos="$." norm=".">.</w>
  34. </s>
  35. </text>

List

  1. ['In', 'ihm', 'war', 'das', 'Leben', '/', 'und', 'das', 'Leben', 'war', 'das', 'Licht', 'der', 'Menschen', '/', 'und', 'das', 'Licht', 'scheinet', 'in', 'der', 'Finsternis', '/', 'und', 'die', 'Finsternis', 'habens', 'nicht', 'begriffen', '.']