예제 #1
0
def generate_templates(label,project_name,depth=1,output_file="sentence_and_template_generator", paraphraser=False):
    """
    The function acts as a wrapper for the whole package of supplied source code.
    """
    val = generate_url(label)
    url = val[0]
    about = (val[1])
    count =0
    vessel= []  
    depth=int(depth)
    diction = fetch_ranks("../utility/part-r-00000")
    if(not os.path.isdir(project_name)):
        os.makedirs(project_name)
    output_file = open(project_name+"/" + output_file, 'w')
    test_set = open(project_name+"/" + "test.csv", 'w')
    if paraphraser:
        expand_set = open(project_name+"/" + "expand.csv", 'w')
    prop_dic = {}
    for iterator in range(depth):
        prop_dic[iterator] = []
    # Create a logger object
    logger = logging.getLogger()

    # Configure logger
    logging.basicConfig(filename=project_name+"/logfile.log", format='%(filename)s: %(message)s', filemode='w')

    # Setting threshold level
    logger.setLevel(logging.WARNING)

    # Use the logging methods
    #logger.debug("This is a debug message")  
    logger.info("This is a log file.")  
    #logger.warning("This is a warning message")  
    #logger.error("This is an error message")  
    #logger.critical("This is a critical message")
    if paraphraser:
        folder_path = get_pretrained_model(const.URL)
        set_seed(42)
        tokenizer, device, model = prepare_model(folder_path)

    list_of_property_information = get_properties(url=url,project_name=project_name,output_file = "get_properties.csv")
    for property_line in list_of_property_information:
        count+=1
        prop = property_line.split(',')
        print("**************\n"+str(prop))
        if paraphraser:
            sentence_and_template_generator(original_count=depth,prop_dic=prop_dic,test_set=test_set,log=logger,diction=diction,output_file=output_file,mother_ontology=about.strip().replace("http://dbpedia.org/ontology/","dbo:"),vessel=vessel,project_name=project_name ,prop=prop, suffix = " of <A> ?",count = depth,expand_set=expand_set,tokenizer=tokenizer,device=device,model=model)
        else:
            sentence_and_template_generator(original_count=depth, prop_dic=prop_dic, test_set=test_set, log=logger,
                                            diction=diction, output_file=output_file,
                                            mother_ontology=about.strip().replace("http://dbpedia.org/ontology/",
                                                                                  "dbo:"), vessel=vessel,
                                            project_name=project_name, prop=prop, suffix=" of <A> ?", count=depth)

    output_file.close()
예제 #2
0
def generate_templates(label,project_name,depth=1,output_file="sentence_and_template_generator"):
    """
    Funtion to generate templates | wrapper function for rest of the functions. 
    """
    val = generate_url(label)
    url = val[0]
    about = (val[1])
    count =0
    vessel= []  
    
    diction = fetch_ranks("../utility/part-r-00000")
    if(not os.path.isdir(project_name)):
        os.makedirs(project_name)
    output_file = open(project_name+"/" + output_file, 'w')
    
    # Create a logger object
    logger = logging.getLogger()

    # Configure logger
    logging.basicConfig(filename=project_name+"/logfile.log", format='%(filename)s: %(message)s', filemode='w')

    # Setting threshold level
    logger.setLevel(logging.DEBUG)

    # Use the logging methods
    #logger.debug("This is a debug message")  
    logger.info("This is a log file.")  
    #logger.warning("This is a warning message")  
    #logger.error("This is an error message")  
    #logger.critical("This is a critical message")   

    list_of_property_information = get_properties(url=url,project_name=project_name,output_file = "get_properties.csv")
    for property_line in list_of_property_information:
        count+=1
        prop = property_line.split(',')
        print("**************\n"+str(prop))
        sentence_and_template_generator(log=logger,diction=diction,output_file=output_file,mother_ontology=about.strip().replace("http://dbpedia.org/ontology/","dbo:"),vessel=vessel,project_name=project_name ,prop=prop, suffix = " of <A> ?",count = 2)
    output_file.close()