#!/usr/bin/python

"""
Domain model for NED, NewsReader project.

@author: U{Filip Ilievski<filipilievski.wordpress.com>}
@author: U{Antske Fokkens<http://wordpress.let.vupr.nl/antske/>}
@version: 0.1
@contact: U{f.ilievski@vu.nl<mailto:f.ilievski@vu.nl>}
@contact: U{antske.fokkens@vu.nl<mailto:antske.fokkens@vu.nl>}
@since: 08-Jul-2015
"""

__version__ = '0.1'
__modified__ = '08Jul2015'
__author__ = 'Filip Ilievski, Antske Fokkens'

from KafNafParserPy import *
import os
import sys
import json
import time
sys.path.append('./')
from dbpediaEnquirerPy import *

##########################################################################################
################################### HELPER FUNCTIONS #####################################
##########################################################################################

def get_start_term(parser):
	# Find the start of sentence 2 (after title)
	for token in parser.get_tokens():
		if token.get_sent()=="2":
			token_after_title=int(token.get_id().replace("w", ""))
			break		
	# Process from sentence 2 on
	# First find the appropriate term where sentence 2 starts
	for term in parser.get_terms():
		target_ids=term.get_span().get_span_ids()
		if int(target_ids[0].replace("w", ""))>=token_after_title:
			term_after_title=int(term.get_id().replace("t", ""))
			break
	return term_after_title

def get_most_confident_link(e):
	maxconf=-0.1
	maxref=None
	for ref in e.get_external_references():
		if ref.get_resource()=="spotlight_v1" and float(ref.get_confidence())>maxconf:
			maxconf=float(ref.get_confidence())
			maxref=ref.get_reference()
	return maxref