<commit_before>import sqlite3, sys, SQLite, igraph, csv, senGraph, datetime

# TODO:
# Calculate component ranking and assign a component identifier
# Calculate eigenvector centrality within components
# Add function to get vertices of the component number

# Option 1: run the script directly from the command line
# TODO: implement this!

def time_printer(program_start = 0, calc_start = 0):
    now = datetime.datetime.now()
    if(program_start):
        print "Time elapsed: ", now - program_start
    if(calc_start):
        print "Calculation time: ", now - calc_start

def DVN_script(filepath = "/home/ayu/DVN/", dbnames = []):
    """
    script to create and run DVN object from command line

    To run:
    python DVN.py <directory> <database names - variable length, separate by spaces>

    Example:
    python DVN.py /home/ayu/DVN/ invpat
    
    (1) Create network data files based on invpat for upload to DVN (graphml format)
    (2) Create csv files for data and pre-calculated network measures
        network measures calculated:
            node measures:
                - centrality (degree, betweenness)
                - clustering coefficient
                - constraint
                - component number
            edge measures:
                - betweenness
    
    """
    t1 = datetime.datetime.now()
    print "Start", t1   
    print filepath
    print dbnames
    D = DVN(filepath, dbnames)
    D.create_graphs()
##    print "calculating node betweenness.."
##    D.calculate_node_betweenness()
##    print "calculating pagerank..."
##    D.calculate_PageRank()
##    print "calculating edge betweenness..."
##    D.calculate_edge_betweenness()
    time_printer(t1)
    t2 = datetime.datetime.now()
    print "calculating constraint..."
    D.calculate_constraint()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "calculating transitivity..."
    D.calculate_clustering_coefficient()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "calculating degree..."
    D.calculate_degree()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "calculating component ranking..."
    D.calculate_component()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "calculating eigenvector centrality..."
    D.calculate_eigenvector_centrality()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "calculating subclasses..."
    D.calculate_subclasses()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "calculating citation counts..."
    D.calculate_citations()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "calculating total inventors per patent..."
    D.calculate_inventor_count()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    D.summary()
    print "creating graphml network files for 2000-2003"
    D.create_graphml_file(year=2000)
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "creating csv files for 2000-2006"
    D.create_csv_file()
    time_printer(t1, t2)
    print "DONE"
    time_printer(t1)
    

# Option 2: run interactively in Python
# create a DVN object, various functions available within to use and reuse

class DVN():
    """
    initialize a DVN object for uploading patent data to the IQSS DVN
    """

    def __init__(self, filepath, dbnames, graphml = '', begin = 2000, end = 2006, increment = 3):
        """
        takes a filepath string and a list of dbnames
        if graphml files already exist, take the list of files and read into graph list as graph objects

        ex:
        import DVN
        D = DVN.DVN(filepath='/home/ayu/DVN/', dbnames=['patent', 'invpat', 'citation', 'class'], graphml = ['pat_2000.graphml', 'pat_2003.graphml'])
        D.summary()
        D.create_csv_file()
        """
        self.filepath = filepath<commit_msg>changed DVN to calculate for all years<commit_after>import sqlite3, sys, SQLite, igraph, csv, senGraph, datetime

# TODO:
# Calculate component ranking and assign a component identifier
# Calculate eigenvector centrality within components
# Add function to get vertices of the component number

# Option 1: run the script directly from the command line
# TODO: implement this!

def time_printer(program_start = 0, calc_start = 0):
    now = datetime.datetime.now()
    if(program_start):
        print "Time elapsed: ", now - program_start
    if(calc_start):
        print "Calculation time: ", now - calc_start

def DVN_script(filepath = "/home/ayu/DVN/", dbnames = []):
    """
    script to create and run DVN object from command line

    To run:
    python DVN.py <directory> <database names - variable length, separate by spaces>

    Example:
    python DVN.py /home/ayu/DVN/ invpat
    
    (1) Create network data files based on invpat for upload to DVN (graphml format)
    (2) Create csv files for data and pre-calculated network measures
        network measures calculated:
            node measures:
                - centrality (degree, betweenness)
                - clustering coefficient
                - constraint
                - component number
            edge measures:
                - betweenness
    
    """
    t1 = datetime.datetime.now()
    print "Start", t1   
    print filepath
    print dbnames
    D = DVN(filepath, dbnames)
    D.create_graphs()
##    print "calculating node betweenness.."
##    D.calculate_node_betweenness()
##    print "calculating pagerank..."
##    D.calculate_PageRank()
##    print "calculating edge betweenness..."
##    D.calculate_edge_betweenness()
    time_printer(t1)
    t2 = datetime.datetime.now()
    print "calculating constraint..."
    D.calculate_constraint()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "calculating transitivity..."
    D.calculate_clustering_coefficient()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "calculating degree..."
    D.calculate_degree()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "calculating component ranking..."
    D.calculate_component()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "calculating eigenvector centrality..."
    D.calculate_eigenvector_centrality()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
##    print "calculating subclasses..."
##    D.calculate_subclasses()
##    time_printer(t1, t2)
##    t2 = datetime.datetime.now()
##    print "calculating citation counts..."
##    D.calculate_citations()
##    time_printer(t1, t2)
##    t2 = datetime.datetime.now()
##    print "calculating total inventors per patent..."
##    D.calculate_inventor_count()
##    time_printer(t1, t2)
##    t2 = datetime.datetime.now()
    D.summary()
    print "creating graphml network files for 2000-2003"
    D.create_graphml_file()
    time_printer(t1, t2)
    t2 = datetime.datetime.now()
    print "creating csv files for 1975-2010"
    D.create_csv_file()
    time_printer(t1, t2)
    print "DONE"
    time_printer(t1)
    

# Option 2: run interactively in Python
# create a DVN object, various functions available within to use and reuse

class DVN():
    """
    initialize a DVN object for uploading patent data to the IQSS DVN
    """

    def __init__(self, filepath, dbnames, graphml = '', begin = 1975, end = 2010, increment = 3):
        """
        takes a filepath string and a list of dbnames
        if graphml files already exist, take the list of files and read into graph list as graph objects

        ex:
        import DVN
        D = DVN.DVN(filepath='/home/ayu/DVN/', dbnames=['patent', 'invpat', 'citation', 'class'], graphml = ['pat_2000.graphml', 'pat_2003.graphml'])
        D.summary()
        D.create_csv_file()
        """
        self.filepath = filepath
{'fraction_non_alphanumeric': 0.10436456996148909, 'fraction_numerical': 0.01951219512195122, 'mean_word_length': 2.806057645334636, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1123292', 'n_tokens_mistral': 2536, 'n_tokens_neox': 2353, 'n_words': 695}