简体   繁体   中英

TypeError: unorderable types: int() < str()

There is an error occurs when I was applying the 5W1H extractor(which is an opensource library in Git) on my JSON news dataset.

The error occurs at evaluate_location file when it tried to run

raw_locations.sort(key=lambda x: x[1], reverse=True)

Then the console gave the error says

TypeError: unorderable types: int() < str()

My question is: Does this means something wrong with my dataset format? But if so shouldn't it consider all the news data as a simple long string when the extractor work on this corpus? I'm eagerly looking for a solution to this problem.

This is one of the json news data:

{
"title": "Football: Van Dijk, Ronaldo and Messi shortlisted for FIFA award",
"body": "ROME: Liverpool centre-back Virgil van Dijk is on the shortlist to add FIFA's best player award to his UEFA Men's Player of the Year honour.The Dutch international denied Cristiano Ronaldo and Lionel Messi for the European title last week and the same trio are in the running for the FIFA accolade to be announced in Milan on September 23.    Van Dijk starred in Liverpool's triumphant Champions League campaign.England full-back Lucy Bronze won UEFA's women's award and is on FIFA's shortlist with the United States' World Cup-winning duo Megan Rapinoe and Alex Morgan.Manchester City boss Pep Guardiola is up against Liverpool's Jurgen Klopp and Mauricio Pochettino of Tottenham for best men's coach.Phil Neville, who led England's women to a World Cup semi-final, is up for the women's coach award with the USA's Jill Ellis and Sarina Wiegman who guided European champions the Netherlands to the World Cup final.    FIFA Best shortlistsMen's player:Cristiano Ronaldo (Juventus/Portugal), Lionel Messi (Barcelona/Argentina), Virgil van Dijk  player:Lucy Bronze (Lyon/England), Alex Morgan (Orlando Pride/USA), Megan Rapinoe (Reign FC/USA)Men's coach:Pep Guardiola (Manchester City), Jurgen Klopp (Liverpool), Mauricio Pochettino (Tottenham)Women's coach:Jill Ellis (USA), Phil Neville (England), Sarina Wiegman (Netherlands)Women's goalkeeper:Christiane Endler (Paris St-Germain/Chile), Hedvig Lindahl (Wolfsburg/Sweden), Sari van Veenendaal (Atletico Madrid/Netherlands)Men's goalkeeper:Alisson (Liverpool/Brazil), Ederson (Manchester City/Brazil), Marc-Andre ter Stegen (Barcelona/Germany)Puskas award (for best goal):Lionel Messi (Barcelona v Real Betis), Juan Quintero (River Plate v Racing Club), Daniel Zsori (Debrecen v Ferencvaros)",
"published_at": "2019-09-02",
} 

Code:

json_file = open("./Labeled.json","r",encoding="utf-8")
data = json.load(json_file)

if __name__ == '__main__':
    # logger setup
    log = logging.getLogger('GiveMe5W')
    log.setLevel(logging.DEBUG)
    sh = logging.StreamHandler()
    sh.setLevel(logging.DEBUG)
    log.addHandler(sh)

    # giveme5w setup - with defaults
    extractor = MasterExtractor()
    Document() 

for i in range(0,1000):
    body = data[i]["body"]
    #print(body)
    #for line in body:
    #print(line[0:line.find('\n')])
    #head = re.sub("[^A-Z\d]", "", "")
    head = re.search("^[^\n]*", body).group(0)
    head = str(head)

    title = data[i]["title"]
    title = str(title)

    body = data[i]["body"]
    body = str(body)

    published_at = data[i]["published_at"]
    published_at = str(published_at)

    doc1 = Document(title,head,body,published_at)


    doc = extractor.parse(doc1)

Instead of return the extracted time&location result, it gave me this error:

 Traceback (most recent call last):   File
 "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
     self.run()   File "/usr/local/lib/python3.5/dist-packages/Giveme5W1H/extractor/extractor.py",
 line 20, in run
     extractor.process(document)   File "/usr/local/lib/python3.5/dist-packages/Giveme5W1H/extractor/extractors/abs_extractor.py",
 line 41, in process
     self._evaluate_candidates(document)   File "/usr/local/lib/python3.5/dist-packages/Giveme5W1H/extractor/extractors/environment_extractor.py",
 line 75, in _evaluate_candidates
     locations = self._evaluate_locations(document)   File "/usr/local/lib/python3.5/dist-packages/Giveme5W1H/extractor/extractors/environment_extractor.py",
 line 224, in _evaluate_locations
     raw_locations.sort(key=lambda x: x[1], reverse=True) TypeError: unorderable types: int() < str()

The row_locations is build in the same file in line 219:

raw_locations.append([parts, location.raw['place_id'], location.point, bb, area, 0, 0, candidate, 0])

Thus, the sort function tries to sort the locations by their place_id . Please check your dataset if it does include strings and numbers for the place_id . If so you need to convert all entries to one type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM