sobir-hf commited on
Commit
518362d
·
1 Parent(s): e00c03d

updated format and data

Browse files
Files changed (2) hide show
  1. annotations_parser.py +10 -10
  2. data.jsonl +0 -0
annotations_parser.py CHANGED
@@ -9,8 +9,8 @@ def parse_annotated_text(text):
9
  # This variable will keep track of the number of characters removed
10
  chars_removed = 0
11
 
12
- # This will store the positions of the entities in the original text
13
- positions_in_original_text = []
14
 
15
  # Buffer to store content without annotations
16
  buffer = []
@@ -40,12 +40,12 @@ def parse_annotated_text(text):
40
  buffer.append(text[last_end:start])
41
  buffer.append(entity)
42
 
43
- # Calculate the start and end positions in the original text
44
  original_start = start - chars_removed
45
  original_end = original_start + len(entity)
46
 
47
- # Store the positions
48
- positions_in_original_text.append((original_start, original_end))
49
 
50
  # update the chars_removed counter
51
  chars_removed += len(full_match) - len(entity)
@@ -61,7 +61,7 @@ def parse_annotated_text(text):
61
 
62
  return {
63
  'text': content_without_annotations,
64
- 'positions': positions_in_original_text,
65
  'labels': labels
66
  }
67
 
@@ -99,7 +99,7 @@ def load_yedda_annotations(directory):
99
  'file': filename,
100
  'annotated_text': content,
101
  'text': parsed['text'],
102
- 'positions': parsed['positions'],
103
  'labels': parsed['labels'],
104
  }
105
  all_annotations.append(file_annotations)
@@ -111,7 +111,7 @@ def convert_to_ann(annotatations):
111
  text = annotatations['text']
112
  buffer = []
113
  i = 0
114
- for (j_start, j_end), label in zip(annotatations['positions'], annotatations['labels']):
115
 
116
  buffer += text[i:j_start]
117
  buffer += [f'[@{text[j_start:j_end]}#{label}*]']
@@ -133,8 +133,8 @@ if __name__ == '__main__':
133
  print('File:', file_annotation['file'])
134
  print('Text[:100]:', repr(file_annotation['text'][:100]))
135
  print('Number of labels:', len(file_annotation['labels']))
136
- assert len(file_annotation['labels']) == len(file_annotation['positions'])
137
- print('Average labeled sentence length:', sum(end-start for start,end in file_annotation['positions']) / len(file_annotation['positions']))
138
  print('--------------------------------')
139
 
140
  print('Total number of files:', len(annotations))
 
9
  # This variable will keep track of the number of characters removed
10
  chars_removed = 0
11
 
12
+ # This will store the spans of the entities in the original text
13
+ spans_in_original_text = []
14
 
15
  # Buffer to store content without annotations
16
  buffer = []
 
40
  buffer.append(text[last_end:start])
41
  buffer.append(entity)
42
 
43
+ # Calculate the start and end spans in the original text
44
  original_start = start - chars_removed
45
  original_end = original_start + len(entity)
46
 
47
+ # Store the spans
48
+ spans_in_original_text.append((original_start, original_end))
49
 
50
  # update the chars_removed counter
51
  chars_removed += len(full_match) - len(entity)
 
61
 
62
  return {
63
  'text': content_without_annotations,
64
+ 'spans': spans_in_original_text,
65
  'labels': labels
66
  }
67
 
 
99
  'file': filename,
100
  'annotated_text': content,
101
  'text': parsed['text'],
102
+ 'spans': parsed['spans'],
103
  'labels': parsed['labels'],
104
  }
105
  all_annotations.append(file_annotations)
 
111
  text = annotatations['text']
112
  buffer = []
113
  i = 0
114
+ for (j_start, j_end), label in zip(annotatations['spans'], annotatations['labels']):
115
 
116
  buffer += text[i:j_start]
117
  buffer += [f'[@{text[j_start:j_end]}#{label}*]']
 
133
  print('File:', file_annotation['file'])
134
  print('Text[:100]:', repr(file_annotation['text'][:100]))
135
  print('Number of labels:', len(file_annotation['labels']))
136
+ assert len(file_annotation['labels']) == len(file_annotation['spans'])
137
+ print('Average labeled sentence length:', sum(end-start for start,end in file_annotation['spans']) / len(file_annotation['spans']))
138
  print('--------------------------------')
139
 
140
  print('Total number of files:', len(annotations))
data.jsonl CHANGED
The diff for this file is too large to render. See raw diff