# Path: pump/vivopump.py
# def get_parms():
#     """
#     Use get_args to get the args, and return a dictionary of the args ready for
#     use in pump software.
#     @see get_args()
# 
#     :return: dict: parms
#     """
#     parms = {}
#     args = get_args()
#     for name, val in vars(args).items():
#         if val is not None:
#             parms[name] = val
#     return parms
# 
# def create_enum(filename, query, parms, trim=0, skip=0):
#     """
#     Given, query, parms and a filename, execute the query and write the enum into the file
#     :param: filename: name of the file to contain the enumeration
#     :param: query: the query to be used to create the columns for the enumeration
#     :param: parms: dictionary of VIVO SPARQL API parameters
#     :param: trim:  If 0, no trim.  If k, return the first k characters as a trimmed value for short
#     :param: skip: If 0, no skip.  If k, skip the first k characters as a trimmed value for short
#     :return: None
#     """
#     import codecs
#     data = vivo_query(query, parms)
#     outfile = codecs.open(filename, mode='w', encoding='ascii', errors='xmlcharrefreplace')
#     outfile.write("short\tvivo\n")
#     for item in data['results']['bindings']:
#         if trim == 0 and skip==0:
#             outfile.write(item["short"]["value"] + "\t" + item["vivo"]["value"] + "\n")
#         elif trim != 0 and skip == 0:
#             outfile.write(item["short"]["value"][:trim] + "\t" + item["vivo"]["value"] + "\n")
#         elif trim == 0 and skip != 0:
#             outfile.write(item["short"]["value"][skip:] + "\t" + item["vivo"]["value"] + "\n")
#         else:
#             outfile.write(item["short"]["value"][skip:-trim] + "\t" + item["vivo"]["value"] + "\n")
#     outfile.close()


from datetime import datetime
from pump.vivopump import get_parms, create_enum
"""



__author__ = "Michael Conlon"
__copyright__ = "Copyright 2017 (c) Michael Conlon"
__license__ = "BSD 3-Clause license"
__version__ = "0.2"


def main():
    """
    Generate the organization enum
    """
    print datetime.now(), "Start"
    parms = get_parms()

    #   Organization

    query = """
    SELECT (MIN (?xlabel) AS ?short) ?vivo
    WHERE
    {
          ?vivo rdf:type foaf:Organization .
          ?vivo rdfs:label ?xlabel .
    }
    GROUP BY ?vivo
    ORDER BY ?short
    """


# Path: pump/vivopump.py
# def get_parms():
#     """
#     Use get_args to get the args, and return a dictionary of the args ready for
#     use in pump software.
#     @see get_args()
# 
#     :return: dict: parms
#     """
#     parms = {}
#     args = get_args()
#     for name, val in vars(args).items():
#         if val is not None:
#             parms[name] = val
#     return parms
# 
# def create_enum(filename, query, parms, trim=0, skip=0):
#     """
#     Given, query, parms and a filename, execute the query and write the enum into the file
#     :param: filename: name of the file to contain the enumeration
#     :param: query: the query to be used to create the columns for the enumeration
#     :param: parms: dictionary of VIVO SPARQL API parameters
#     :param: trim:  If 0, no trim.  If k, return the first k characters as a trimmed value for short
#     :param: skip: If 0, no skip.  If k, skip the first k characters as a trimmed value for short
#     :return: None
#     """
#     import codecs
#     data = vivo_query(query, parms)
#     outfile = codecs.open(filename, mode='w', encoding='ascii', errors='xmlcharrefreplace')
#     outfile.write("short\tvivo\n")
#     for item in data['results']['bindings']:
#         if trim == 0 and skip==0:
#             outfile.write(item["short"]["value"] + "\t" + item["vivo"]["value"] + "\n")
#         elif trim != 0 and skip == 0:
#             outfile.write(item["short"]["value"][:trim] + "\t" + item["vivo"]["value"] + "\n")
#         elif trim == 0 and skip != 0:
#             outfile.write(item["short"]["value"][skip:] + "\t" + item["vivo"]["value"] + "\n")
#         else:
#             outfile.write(item["short"]["value"][skip:-trim] + "\t" + item["vivo"]["value"] + "\n")
#     outfile.close()


# Path: examples/orgs/make_enum.py
from datetime import datetime
from pump.vivopump import get_parms, create_enum

"""



__author__ = "Michael Conlon"
__copyright__ = "Copyright 2017 (c) Michael Conlon"
__license__ = "BSD 3-Clause license"
__version__ = "0.2"


def main():
    """
    Generate the organization enum
    """
    print datetime.now(), "Start"
    parms = get_parms()

    #   Organization

    query = """
    SELECT (MIN (?xlabel) AS ?short) ?vivo
    WHERE
    {
          ?vivo rdf:type foaf:Organization .
          ?vivo rdfs:label ?xlabel .
    }
    GROUP BY ?vivo
    ORDER BY ?short
    """


    create_enum("country_enum.txt", query, parms)