# Path: nordlys/config.py
# DATA_DIR = path.dirname(path.dirname(path.abspath(__file__))) + "/data"
# 
# Path: nordlys/wikipedia/utils.py
# class WikipediaUtils(object):
#     mongo = None
#     
#     @staticmethod
#     def wiki_title_to_uri(title):
#         """
#         Converts wiki page title to wiki_uri
#         based on https://en.wikipedia.org/wiki/Wikipedia:Page_name#Spaces.2C_underscores_and_character_coding
#         encoding based on http://dbpedia.org/services-resources/uri-encoding
#         """
#         if title:
#             wiki_uri = "<wikipedia:" + quote(title, ' !$&\'()*+,-./:;=@_~').replace(' ', '_') + ">"
#             return wiki_uri
#         else:
#             return None
# 
#     @staticmethod
#     def wiki_uri_to_dbp_uri(wiki_uri):
#         """Converts Wikipedia uri to DBpedia URI."""
#         return wiki_uri.replace("<wikipedia:", "<dbpedia:")


import sys
from collections import defaultdict
from nordlys.config import DATA_DIR
from nordlys.wikipedia.utils import WikipediaUtils
"""
Converts the results to ELQ format:
 - Filters general concept entities (keeps only proper noun entities)
 - Creates ELQ format file

@author: Faegheh Hasibi (faegheh.hasibi@idi.ntnu.no)
"""



def load_kb():
    """Loads Freebase snapshot of proper noun entities."""
    print "Loading knowledge base snapshot ..."

# Path: nordlys/config.py
# DATA_DIR = path.dirname(path.dirname(path.abspath(__file__))) + "/data"
# 
# Path: nordlys/wikipedia/utils.py
# class WikipediaUtils(object):
#     mongo = None
#     
#     @staticmethod
#     def wiki_title_to_uri(title):
#         """
#         Converts wiki page title to wiki_uri
#         based on https://en.wikipedia.org/wiki/Wikipedia:Page_name#Spaces.2C_underscores_and_character_coding
#         encoding based on http://dbpedia.org/services-resources/uri-encoding
#         """
#         if title:
#             wiki_uri = "<wikipedia:" + quote(title, ' !$&\'()*+,-./:;=@_~').replace(' ', '_') + ">"
#             return wiki_uri
#         else:
#             return None
# 
#     @staticmethod
#     def wiki_uri_to_dbp_uri(wiki_uri):
#         """Converts Wikipedia uri to DBpedia URI."""
#         return wiki_uri.replace("<wikipedia:", "<dbpedia:")


# Path: scripts/to_elq.py
import sys
from collections import defaultdict
from nordlys.config import DATA_DIR
from nordlys.wikipedia.utils import WikipediaUtils

"""
Converts the results to ELQ format:
 - Filters general concept entities (keeps only proper noun entities)
 - Creates ELQ format file

@author: Faegheh Hasibi (faegheh.hasibi@idi.ntnu.no)
"""



def load_kb():
    """Loads Freebase snapshot of proper noun entities."""
    print "Loading knowledge base snapshot ..."

    __fb_dbp_file = open(DATA_DIR + "/fb_dbp_snapshot.txt", "r")