PKG-INFO 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. Metadata-Version: 1.0
  2. Name: pandasToBrat
  3. Version: 1.1.1
  4. Summary: Function for Brat folder administration from Python and Pandas object.
  5. Home-page: UNKNOWN
  6. Author: Ali BELLAMINE
  7. Author-email: contact@alibellamine.me
  8. License: UNKNOWN
  9. Description: # pandasToBrat
  10. Ali BELLAMINE - contact@alibellamine.me
  11. _Last version : 1.0 - 28/10/2020_
  12. ## What is pandasToBrat ?
  13. pandasToBrat is a library to manage brat configuration and brat data from a Python interface.
  14. ### What can it do ?
  15. - Reading brat annotations and relations configuration to python dictionnary
  16. - Writting brat annotations and relations configuration from python dictionnary
  17. - Reading brat text data to python pandas dataframe
  18. - Writting brat text file from python pandas Series
  19. - Reading brat annotations and relations
  20. - Writting brat annotations and relations from python pandas DataFrame
  21. - Export data to ConLL-2003 format
  22. ### What it doesn't support ?
  23. - Keyboard shortcut configuration
  24. - Event, Attribution, Modification, Normalization and Notes annotations
  25. - Relation type in relations configuration
  26. ## How to use it ?
  27. ### Installation
  28. Clone the current repository :
  29. ```
  30. git clone https://gogs.alibellamine.me/alibell/pandasToBrat
  31. ```
  32. Install dependencies with pip.
  33. ```
  34. pip install -r requirements.txt
  35. ```
  36. Then install the library :
  37. ```
  38. pip install -e .
  39. ```
  40. ### Loading a brat folder
  41. Instantiate the brat library with the folder path :
  42. ```
  43. from pandasToBrat import pandasToBrat
  44. brat_data = pandasToBrat(FOLDER_PATH)
  45. ```
  46. ### Parameters
  47. Parameters are stored in a dictionnary :
  48. ```
  49. {
  50. "entities":ENTITIES_CONFIGURATION_DATA,
  51. "relations":RELATIONS_CONFIGURATION_DATA
  52. }
  53. ```
  54. #### Entities configuration data
  55. Dictionnary formated as :
  56. ```
  57. {
  58. LABEL_NAME:{
  59. LABEL_NAME_CHILD1:True,
  60. LABEL_NAME_CHILD2:True,
  61. LABEL_NAME_CHILD3:{
  62. LABEL_NAME_CHILD3_CHILD1:True
  63. }
  64. }
  65. }
  66. ```
  67. Each entry is an entitie.
  68. An entitie can either be setted as True, it have no child, or have on or many childrens in which case is contains a dictionnary.
  69. #### Relations configuration data
  70. Dictionnary formated as :
  71. ```
  72. {
  73. RELATION_NAME:{
  74. "args":[ENTITIES_NAME,...]
  75. }
  76. }
  77. ```
  78. Each entrie of the dictionnary is a relation.
  79. Each relation have a relation name and defined with a sub-dictionnary containing an args entrie.
  80. The args entrie contains a list of entities that are concerned by the relation.
  81. #### Read and write parameters
  82. ##### Getting parameters
  83. You can read the current parameters using the dedicated method :
  84. ```
  85. bratData.read_conf()
  86. ```
  87. ##### Writtings parameters
  88. You can write parameters using the dedicated method :
  89. ```
  90. bratData.write_conf(entities = ENTITIES_CONFIGURATION, relations = RELATIONS_CONFIGURATION)
  91. ```
  92. The ENTITIES_CONFIGATION is a dictionnary formated as described in the "Entities configuration data" chapter.
  93. The RELATIONS_CONFIGURATION is a dictionnary formated as described in the "Relations configuration data" chapter.
  94. ### Text
  95. Text is stored in a Pandas Dataframe with two columns :
  96. - id : document id, which is contained in the .txt filename
  97. - text_data : document data
  98. #### Read and write text
  99. ##### Getting text data
  100. ```
  101. bratData.read_text()
  102. ```
  103. #### Sending text data
  104. ```
  105. bratData.write_text(text_id=TEXT_ID_SERIES, text = TEXT_SERIES, empty = EMPTY_PARAMETER, overWriteAnnotations = OVERWRITE_ANNOTATIONS_PARAMETERS)
  106. ```
  107. The required parameters are text_id and text which are Pandas Series, which should be of the same size containing for the first one the document unique id and the second one the document text data.
  108. The empty parameters is used to empty the current folder. If set as True, the Brat folder is emptied of all text and annotations data. Configuration is not erased.
  109. The overwrite annotations parameter is used to overwrite the current annotation (.ann) file with an empty one, it is useful if you want to remove the existing annotations when you are modifiying a text file.
  110. This way, you can :
  111. - Overwrite all data with empty set as True
  112. - Only overwritting new data with empty set as False and overWriteAnnotations set as True : you write new file, if the id already exist it is overwritten, if not is it ignored.
  113. ### Annotations
  114. Parameters are stored in a dictionnary :
  115. ```
  116. {
  117. "annotations":ANNOTATIONS_ANNOTATIONS,
  118. "relations":RELATIONS_ANNOTATIONS
  119. }
  120. ```
  121. #### Annotations format
  122. Annotations are word labeled with entities.
  123. It is formatted as a Pandas DataFrame, containing the following columns :
  124. - id : Document id, one document can have mutiples annotations
  125. - type_id : annotation number inside the same document, from T1 to Tn, with n the number of annotated string, it is used to match annotations with relations
  126. - word : the annotated string
  127. - label : the entitie related to the annotated string
  128. - start : the annotated string start offset
  129. - end : the annotated string end offset
  130. #### Relations format
  131. Annotations are relations between annotations.
  132. It is formatted as a Pandas DataFrame, containing the following columns :
  133. - id : Document id, one document can have mutiples relations
  134. - type_id : relation number inside the same document, from R1 to Rn, with n the number of relations
  135. - relation : The relation Name
  136. - ArgX : The annotated entitie which a linked by the relation, each column refer to an entitie, the entitie id correspond to the annotations DataFrame "type_id" column
  137. #### Read and write annotations
  138. ##### Getting annotations data
  139. ```
  140. bratData.read_annotation()
  141. ```
  142. #### Sending annotations data
  143. ##### Write annotations subpart of annotations
  144. ```
  145. bratData.write_annotations(df, text_id, word, label, start, end, overwrite=OVERWRITE_OPTION)
  146. ```
  147. The first parameter is the datafame containing the annotations.
  148. It should be formated as described in the "Annotations format" subpart.
  149. The text_id, word, label, start and end are the name of the column inside the dataframe which contains the related data.
  150. The overwrite option can be set as True to overwrite existing annotations, otherwise the dataframe's data are added to existing annotations data.
  151. ##### Write relations subpart of annotations
  152. ```
  153. bratData.write_relations(df, relation, overwrite=OVERWRITE_OPTION)
  154. ```
  155. The first parameter is the datafame containing the relations.
  156. It should be formated as described in the "Relations format" subpart.
  157. The text_id and relation are the name of the column inside the dataframe which contains the related data.
  158. The other columns should contains the type_id of related entities, as outputed by the read_annotation method.
  159. The overwrite option can be set as True to overwrite existing annotations, otherwise the dataframe's data are added to existing annotations data.
  160. ### Export data to standard format
  161. The only currently supported format is ConLL-2003.
  162. To export data, you can use the export method.
  163. ```
  164. bratData.export(export_format = EXPORT_FORMAT, tokenizer = TOKENIZER, entities = ENTITIES_OPTION, keep_empty = KEEP_EMPTY_OPTION)
  165. ```
  166. The export_format parameter is used to specify the export format. The only one, which is the default one, supported is ConLL-2003.
  167. The tokenizer parameter contains the tokenizer functions. Tokenizers functions are stored in pandasToBrat.extract_tools. The aim of the function is to generate tokens and pos tag from text. The default one, _default_tokenizer_, is the simplest one, that split on space and new line character.
  168. You can also use Spacy tokenizer, in that case you should import the spacy_tokenizer functions as demonstrated in this example :
  169. ```
  170. from pandasToBrat.extract_tools import spacy_tokenizer
  171. import spacy
  172. nlp = spacy.load(SPACY_MODEL)
  173. spacy_tokenizer_loaded = spacy_tokenizer(nlp)
  174. bratData.export(tokenizer = spacy_tokenizer_loaded)
  175. ```
  176. You can restrict the export to a limited set of entities. For that, the list of entities are specified in the entities parameter. If set as None, which is the default value, all entities will we considered. If a word contains many entities, the last one is kept.
  177. Finally, the keep_empty option is defaultly set as False. This means that every empty tokens will be removed from the exported data.
  178. You can set it as True if you want to keep empty tokens.
  179. Platform: UNKNOWN