Beispiel #1
0
    def get_info_from_so_files(self):
        nltk_formatter = NLTKFormatter()

        for file_name in os.listdir(self.so_questions):
            file_path = self.so_questions + "/" + file_name
            self.log_writer.write_info_log("Reading StackOverflow questions from " + file_name)

            '''
            json_file_path = ""
            if file_name == "python_title_answer.txt":
                json_file_path = self.so_python_json_path
            else:
                json_file_path = self.so_java_json_path
            '''

            with open(file_path, 'r', encoding='UTF-8') as tsv:
                for line in csv.reader(tsv, dialect="excel-tab"):
                    try:
                        fci_object = FormattedCodeInterface()
                        fci_object.set_content(nltk_formatter.format_sentence(line[2]))
                        fci_object.set_code(line[3])
                        self.save_fci_object_to_json_files(fci_object, self.so_json_path)
                        self.log_writer.write_info_log("Reading StackOverflow question " + line[0])
                    except Exception as e:
                        self.log_writer.write_error_log(e)
    def save_file_details_to_fci_object(self, file_path, file_name):
        fci = FormattedCodeInterface()

        fci.set_file_name(file_name)
        fci.set_save_path(file_path)
        self.set_content(file_path, fci)
        self.set_project_details(fci)

        self.files_in_project.append(fci)
        self.log_writer.write_info_log(file_path + " documented.")
Beispiel #3
0
    def save_file_details_to_fci_object(self, file_path, file_name):
        fci_object = FormattedCodeInterface()

        fci_object.set_file_name(file_name)
        fci_object.set_save_path(file_path)
        self.set_content(file_path, fci_object)
        self.set_project_details(fci_object)

        self.save_fci_objects_to_json_files(fci_object, file_name)
        self.log_writer.write_info_log(file_name + " saved to server at " +
                                       file_path)
Beispiel #4
0
    def save_file_details_to_fci_object(self, file_path, file_name):
        fci_object = FormattedCodeInterface()

        fci_object.set_file_name(file_name)
        fci_object.set_save_path(file_path)
        # self.set_content(file_path, fci_object)

        # Content
        file = open(file_path, encoding='UTF-8')
        content = ''
        for line in file.readlines():
            content += line
        fci_object.set_content(content)
        file.close()

        self.set_project_details(fci_object)

        if file_path.endswith(".py"):
            self.save_fci_object_to_json_files(fci_object, self.python_json_path, file_name)
        else:
            self.save_fci_object_to_json_files(fci_object, self.java_json_path, file_name)

        self.log_writer.write_info_log(file_name + " saved to server at " + file_path)
Beispiel #5
0
    def get_info_from_so_files(self):
        '''
        with open("python_title_answer.txt", 'r', encoding='UTF-8') as tsv:
        #with open("python_title_answer.txt", 'r', encoding='UTF-8') as f:
            for line in csv.reader(tsv, dialect="excel-tab"):
                try:
                    content = line[2]
                    code = line[3]
                    fci_object = FormattedCodeInterface()
                    fci_object.set_content(line[2])
                    fci_object.set_code(line[3])
                    print(line[2])
                    print(line[3])
                except Exception as e:
                    print(e)
        '''

        #file = open('python_title_answer.txt', 'r', encoding='UTF-8')
        #f = open('python_title_answer.txt', 'rb')
        f = open('python_title_answer.txt')
        '''
        content =''
        for line in file.readlines():
            content += line
        print(content)
        '''
        data = []
        for line in f:
            # Remove the new line at the end and then split the string based on
            # tabs. This creates a python list of the values.
            # el = line.encode('utf8')
            values = line.split('\t')
            content = values[2]
            # code = values[3].encode('UTF-8')
            code = values[3]
            print(code)
            fci_object = FormattedCodeInterface()
            fci_object.set_content(content)
            fci_object.set_code(code)
            FCIConverter.to_local_json_file("json_files", fci_object)
            # values = dl.strip().split('\t')
            # data.append([float(v) for v in values])
        print(data)
        f.close()  # close the file'''
Beispiel #6
0
def set_json_data(json_file):
    fci = FormattedCodeInterface()
    data = json.load(open(json_file))

    fci.set_author(data["items"][0]["owner"]["login"])
    fci.set_description(data["items"][0]["description"])
    fci.set_language(data["items"][0]["language"])
    fci.set_project_name(data["items"][0]["name"])
    #fci.set_quality(data["items"][0]["owner"])
    fci.set_save_time(data["items"][0]["owner"])
    fci.set_update_at(data["items"][0]["updated_at"])

    FCI.FCIConverter.to_json_file("json_files", fci)
    '''