# Path: citation_extractor/io/brat.py
# def read_ann_file(fileid, ann_dir, suffix="-doc-1.ann"):
#     """Reads annotations from a brat standoff file.
# 
#     :param fileid:
#     :type fileid:
#     :param ann_dir:
#     :type ann_dir:
#     :returns:
#     :rtype: tuple
#     """
#     ann_file = "%s%s%s"%(ann_dir,fileid,suffix)
#     f = codecs.open(ann_file,'r','utf-8')
#     data = f.read()
#     f.close()
#     rows = data.split('\n')
#     entities = {}
#     ent_count = 0
#     relations = {}
#     annotations = []
#     for row in rows:
#         cols = row.split("\t")
#         ann_id = cols[0]
# 
#         if(u"#" in cols[0]):
#             # it's a text annotation
#             tmp = {
#                 "ann_id":"%s%s"%(cols[1].split()[0],cols[0])
#                 ,"anchor":cols[1].split()[1:][0]
#                 ,"text":cols[2]
#             }
#             annotations.append(tmp)
# 
#         elif(len(cols)==3 and u"T" in cols[0]):
#             # it's an entity
#             ent_count += 1
#             ent_type = cols[1].split()[0]
#             ranges = cols[1].replace("%s"%ent_type,"")
#             entities[cols[0]] = {"ann_id":ann_id
#                                 ,"entity_type": ent_type
#                                 ,"offset_start":ranges.split()[0]
#                                 ,"offset_end":ranges.split()[1]
#                                 ,"surface":cols[2]}
# 
#         elif(len(cols)>=2 and u"R" in cols[0]):
#             # it's a relation
#             rel_type, arg1, arg2 = cols[1].split()
#             relations[cols[0]] = {
#                 "ann_id": ann_id,
#                 "arguments": (arg1.split(":")[1], arg2.split(":")[1]),
#                 "relation_type":rel_type
#             }
# 
#     return entities, relations, annotations


import logging
import codecs
import itertools
import pkg_resources
from citation_extractor.io.brat import read_ann_file as read_ann_file_new
from nltk.classify.scikitlearn import SklearnClassifier
		- otherwise label it as a negative instance.
		- this approach generates way more negative than positive examples
			- when training the classifier select so many negative examples as the positive examples (randomly selected)

	The result returned by this function is a list of lists that looks like this:

	result = [
		[
			[
				"arg1_entity":"AAUTHOR"
				,"arg2_entity":"REFSCOPE"
				,"concent":"AAUTHORREFSCOPE"
				...
			]
			,'scope_pos'
		]
		,[
			[
				"arg1_entity":"REFSCOPE"
				,"arg2_entity":"AAUTHOR"
				,"concent":"REFSCOPEAAUTHOR"
				...
			]
			,'scope_neg'
		]
	]
	"""
	positive_label = "scope_pos"
	negative_label = "scope_neg"
	instances = []

# Path: citation_extractor/io/brat.py
# def read_ann_file(fileid, ann_dir, suffix="-doc-1.ann"):
#     """Reads annotations from a brat standoff file.
# 
#     :param fileid:
#     :type fileid:
#     :param ann_dir:
#     :type ann_dir:
#     :returns:
#     :rtype: tuple
#     """
#     ann_file = "%s%s%s"%(ann_dir,fileid,suffix)
#     f = codecs.open(ann_file,'r','utf-8')
#     data = f.read()
#     f.close()
#     rows = data.split('\n')
#     entities = {}
#     ent_count = 0
#     relations = {}
#     annotations = []
#     for row in rows:
#         cols = row.split("\t")
#         ann_id = cols[0]
# 
#         if(u"#" in cols[0]):
#             # it's a text annotation
#             tmp = {
#                 "ann_id":"%s%s"%(cols[1].split()[0],cols[0])
#                 ,"anchor":cols[1].split()[1:][0]
#                 ,"text":cols[2]
#             }
#             annotations.append(tmp)
# 
#         elif(len(cols)==3 and u"T" in cols[0]):
#             # it's an entity
#             ent_count += 1
#             ent_type = cols[1].split()[0]
#             ranges = cols[1].replace("%s"%ent_type,"")
#             entities[cols[0]] = {"ann_id":ann_id
#                                 ,"entity_type": ent_type
#                                 ,"offset_start":ranges.split()[0]
#                                 ,"offset_end":ranges.split()[1]
#                                 ,"surface":cols[2]}
# 
#         elif(len(cols)>=2 and u"R" in cols[0]):
#             # it's a relation
#             rel_type, arg1, arg2 = cols[1].split()
#             relations[cols[0]] = {
#                 "ann_id": ann_id,
#                 "arguments": (arg1.split(":")[1], arg2.split(":")[1]),
#                 "relation_type":rel_type
#             }
# 
#     return entities, relations, annotations


# Path: citation_extractor/relex/ml.py
import logging
import codecs
import itertools
import pkg_resources
from citation_extractor.io.brat import read_ann_file as read_ann_file_new
from nltk.classify.scikitlearn import SklearnClassifier

		- otherwise label it as a negative instance.
		- this approach generates way more negative than positive examples
			- when training the classifier select so many negative examples as the positive examples (randomly selected)

	The result returned by this function is a list of lists that looks like this:

	result = [
		[
			[
				"arg1_entity":"AAUTHOR"
				,"arg2_entity":"REFSCOPE"
				,"concent":"AAUTHORREFSCOPE"
				...
			]
			,'scope_pos'
		]
		,[
			[
				"arg1_entity":"REFSCOPE"
				,"arg2_entity":"AAUTHOR"
				,"concent":"REFSCOPEAAUTHOR"
				...
			]
			,'scope_neg'
		]
	]
	"""
	positive_label = "scope_pos"
	negative_label = "scope_neg"
	instances = []

	entities, relations, annotations = read_ann_file_new(doc_id, basedir)