mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 09:57:26 +03:00 
			
		
		
		
	* Ensure root albel is spelled ROOT, for backwards compatibility
This commit is contained in:
		
							parent
							
								
									065c2e1d2d
								
							
						
					
					
						commit
						43ef5ddea5
					
				| 
						 | 
					@ -148,6 +148,9 @@ def read_json_file(loc, docs_filter=None):
 | 
				
			||||||
                        tags.append(token['tag'])
 | 
					                        tags.append(token['tag'])
 | 
				
			||||||
                        heads.append(token['head'] + i)
 | 
					                        heads.append(token['head'] + i)
 | 
				
			||||||
                        labels.append(token['dep'])
 | 
					                        labels.append(token['dep'])
 | 
				
			||||||
 | 
					                        # Ensure ROOT label is case-insensitive
 | 
				
			||||||
 | 
					                        if labels[-1].lower() == 'root':
 | 
				
			||||||
 | 
					                            labels[-1] = 'ROOT'
 | 
				
			||||||
                        ner.append(token.get('ner', '-'))
 | 
					                        ner.append(token.get('ner', '-'))
 | 
				
			||||||
                    sents.append((
 | 
					                    sents.append((
 | 
				
			||||||
                        (ids, words, tags, heads, labels, ner),
 | 
					                        (ids, words, tags, heads, labels, ner),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -284,12 +284,14 @@ cdef int _get_root(int word, const GoldParseC* gold) nogil:
 | 
				
			||||||
cdef class ArcEager(TransitionSystem):
 | 
					cdef class ArcEager(TransitionSystem):
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def get_labels(cls, gold_parses):
 | 
					    def get_labels(cls, gold_parses):
 | 
				
			||||||
        move_labels = {SHIFT: {'': True}, REDUCE: {'': True}, RIGHT: {'root': True},
 | 
					        move_labels = {SHIFT: {'': True}, REDUCE: {'': True}, RIGHT: {'ROOT': True},
 | 
				
			||||||
                       LEFT: {'root': True}, BREAK: {'root': True}}
 | 
					                       LEFT: {'ROOT': True}, BREAK: {'ROOT': True}}
 | 
				
			||||||
        for raw_text, sents in gold_parses:
 | 
					        for raw_text, sents in gold_parses:
 | 
				
			||||||
            for (ids, words, tags, heads, labels, iob), ctnts in sents:
 | 
					            for (ids, words, tags, heads, labels, iob), ctnts in sents:
 | 
				
			||||||
                for child, head, label in zip(ids, heads, labels):
 | 
					                for child, head, label in zip(ids, heads, labels):
 | 
				
			||||||
                    if label != 'root':
 | 
					                    if label.upper() == 'ROOT':
 | 
				
			||||||
 | 
					                        label = 'ROOT'
 | 
				
			||||||
 | 
					                    if label != 'ROOT':
 | 
				
			||||||
                        if head < child:
 | 
					                        if head < child:
 | 
				
			||||||
                            move_labels[RIGHT][label] = True
 | 
					                            move_labels[RIGHT][label] = True
 | 
				
			||||||
                        elif head > child:
 | 
					                        elif head > child:
 | 
				
			||||||
| 
						 | 
					@ -302,8 +304,11 @@ cdef class ArcEager(TransitionSystem):
 | 
				
			||||||
                gold.c.heads[i] = i
 | 
					                gold.c.heads[i] = i
 | 
				
			||||||
                gold.c.labels[i] = -1
 | 
					                gold.c.labels[i] = -1
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
 | 
					                label = gold.labels[i]
 | 
				
			||||||
 | 
					                if label.upper() == 'ROOT':
 | 
				
			||||||
 | 
					                    label = 'ROOT'
 | 
				
			||||||
                gold.c.heads[i] = gold.heads[i]
 | 
					                gold.c.heads[i] = gold.heads[i]
 | 
				
			||||||
                gold.c.labels[i] = self.strings[gold.labels[i]]
 | 
					                gold.c.labels[i] = self.strings[label]
 | 
				
			||||||
        for end, brackets in gold.brackets.items():
 | 
					        for end, brackets in gold.brackets.items():
 | 
				
			||||||
            for start, label_strs in brackets.items():
 | 
					            for start, label_strs in brackets.items():
 | 
				
			||||||
                gold.c.brackets[start][end] = 1
 | 
					                gold.c.brackets[start][end] = 1
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user