Exemple #1
0
    def __solve_kana(self):

        for branch in self.__current_branches:
            #The next character in the reading that this branch starts at
            r_index = branch.next_reading
            
            if r_index >= len(self.reading):
                continue
            
            r_char = self.reading[r_index]
            if is_kata(self.__w_char) and is_hira(r_char):
                r_char = hira_to_kata(r_char)
            if is_hira(self.__w_char) and is_kata(r_char):
                r_char = kata_to_hira(r_char) 
        
            if self.__w_char == r_char:
                s = Segment(None, self.__w_char, self.__w_char, 0,
                            self.reading[r_index], self.__w_char)
                n_branch = Branch(branch, s)
                self.__branches_at[self.__w_index+1].append(n_branch)
                self.__usable_branches += 1
Exemple #2
0
def get_id(char, reading):
    """Returns the database id of the reading of char. Reading can be either
    hiragana or katakana (on or kun readings can be found with either)."""

    if len(reading) == 0:
        return None

    conn.row_factory = sqlite3.Row
    # Get both the hiragana and katakana form of reading
    if tools.is_kata(reading[0]):
        k_reading = reading
        h_reading = tools.kata_to_hira(reading)
    else:
        h_reading = reading
        k_reading = tools.hira_to_kata(reading)

    s = "SELECT * FROM reading WHERE character=? and (reading=? or reading=?)"
    result = conn.execute(s, [char, h_reading, k_reading]).fetchall()
    if len(result) <= 0:
        return None
    else:
        return result[0]["id"]