Lab: DBpedia Spotlight

From info216

If you have more time

Task: If you have more time, you can use DBpedia Spotlight to try to link the people (and other "named entities") mentioned in the dataset to DBpedia resources.

pip install pyspotlight

You can start with the code example below, but you will need exception-handling when DBpedia is unable to find a match. For instance:

import spotlight

ENDPOINT = 'https://api.dbpedia-spotlight.org/en/annotate'
CONFIDENCE = 0.5  # filter out results with lower confidence

def annotate_entity(entity_name, filters={'types': 'DBpedia:Person'}):
    annotations = []
    try:
      annotations = spotlight.annotate(ENDPOINT, entity_name, confidence=CONFIDENCE, filters=filters)
    except spotlight.SpotlightException as e:
        # catch exceptions thrown from Spotlight, for example when no DBpedia resource is found
      print(e)
      # handle exceptions here
    return annotations

The example uses the types-filter with DBpedia:Person, because we only want it to match with people. You can choose to only implement the URIs in the response, or the types as well.

Useful materials:

Task: If you have more time, you can use DBpedia Spotlight to try to link the people (and other "named entities") mentioned in the dataset to DBpedia resources.

pip install pyspotlight

You can start with the code example below, but you will need exception-handling when DBpedia is unable to find a match. For instance:

import spotlight

ENDPOINT = 'https://api.dbpedia-spotlight.org/en/annotate'
CONFIDENCE = 0.5  # filter out results with lower confidence

def annotate_entity(entity_name, filters={'types': 'DBpedia:Person'}):
    annotations = []
    try:
	annotations = spotlight.annotate(ENDPOINT, entity_name, confidence=CONFIDENCE, filters=filters)
    except spotlight.SpotlightException as e:
        # catch exceptions thrown from Spotlight, for example when no DBpedia resource is found
	print(e)
	# handle exceptions here
    return annotations

The example uses the types-filter with DBpedia:Person, because we only want it to match with people. You can choose to only implement the URIs in the response, or the types as well.

Useful materials: