728x90
728x90
from datetime import date
from dateutil.relativedelta import relativedelta

today = date.today()

print(today)

sub_date = today - relativedelta(years=2)

print(sub_date)

 

728x90
728x90

ahocorasick 알고리즘은 문자열 검색 알고리즘 중 하나로, 다중 문자열 검색(multiple pattern matching)을 수행하는 알고리즘입니다.

문자열들을 Trie 자료구조로 생성하고, 이를 기반으로 탐색하여 문자열 검사를 실시합니다.

핵심 사항은 검색 하고자하는 문자열을 입력으로 받은 후에 검색이 끝나기전에 검색결과가 나온후에는 다시 앞으로 돌아가는것는 과정이 포함됩니다. 실패 링크

https://ko.wikipedia.org/wiki/%EC%95%84%ED%98%B8_%EC%BD%94%EB%9D%BC%EC%8B%9D_%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98

class Node:
    def __init__(self,text):
        self.text = text
        self.last = 0
        self.output = ""
        self.child = {}
        self.fail = None
        self.rank = 0
    def show(self):
        print( "text:", self.text, "output:",self.output, "fail:", self.fail.text if self.fail is not None else "None","rank:",self.rank)
        if self.last:
            print( "LAST OUTPUT : ", self.output)
        for k in self.child.keys():
            s = self.child[k]
            s.show()
class AhocorasickTrie:
    
    def __init__(self):
        self.no = 0
        self.root = Node(None)
    
    def add(self,text):
        rank = 0
        currentNode = self.root
        for t in text:
            if t not in currentNode.child:
                self.no +=1
                currentNode.child[t] = Node(t)
                print(f"ADD : {t} || Current No. : {self.no}")
            currentNode.rank = rank
            rank+=1
            currentNode = currentNode.child[t]
        currentNode.output = text
        currentNode.last = 1
        currentNode.rank = rank
        print(f"TOTAL : {self.no}")
        
        
    def set_failur(self):
        queue = []
        for c,node in self.root.child.items():
            node.fail = self.root
            queue.append(node)
        while queue:
            currentNode = queue.pop(0)
            for t,node in currentNode.child.items():
                fail_node = currentNode.fail
                while fail_node and t not in fail_node.child:
                    fail_node = fail_node.fail
                if fail_node:
                    node.fail = fail_node.child[t]
                else:
                    node.fail = self.root
                queue.append(node)
    
    def show(self):
        self.root.display()  
        
    def find(self,text):
        result = []
        currentNode = self.root
        for t in text:
            while currentNode is not None and t not in currentNode.child:
                print("fail",currentNode.text)
                currentNode = currentNode.fail
            if t in currentNode.child:
                currentNode = currentNode.child[t]
                if currentNode.output != "":
                    result += [currentNode.output]
                    print(result,t,currentNode.output,currentNode.last,currentNode.output)
                    
        return result

 

728x90
728x90

Trie는 문자열 검색 알고리즘 중 하나로, 문자열을 저장하고 검색하는 데 유용합니다.

이진 탐색 트리와 달리, Trie는 문자열을 저장하는 트리 자료구조입니다.

Trie의 각 노드가 문자열의 한 문자에 대응되는 것입니다.

Trie를 이용해 문자열을 빠르게 검색 할 수 있습니다.

검색을 수행할 문자열을 루트에서 시작해 각 문자에 해당하는 노드들을 따라 검색을 합니다.

class Node:
    def __init__(self,text):
        self.text = text
        self.last = 0
        self.child = {}
        
class Trie:
    
    def __init__(self):
        self.no = 0
        self.root = Node(None)
    
    def add(self,text):
        currentNode = self.root
        for t in text:
            if t not in currentNode.child:
                self.no +=1
                currentNode.child[t] = Node(t)
                print(f"ADD : {t} || Current No. : {self.no}")
            currentNode = currentNode.child[t]
        currentNode.last = 1
        print(f"TOTAL : {self.no}")
        
    def find(self,text):
        result = ""
        currentNode = self.root
        for t in text:
            if t in currentNode.child:
                result += t
                currentNode = currentNode.child[t]
        return result
728x90
728x90

!pip install Selenium

!apt-get update # to update ubuntu to correctly run apt install

!apt install chromium-chromedriver

 

import

 

from selenium import webdriver

728x90
728x90

넘파이 지수/ 로그 함수 

- 로그 함수로 변환

numpy.log1p()

 

- 로그 함수 numpy.log1p()로 변환 된 값을 원래 값으로 변환 

 

numpy.expm1()

728x90
728x90
728x90

+ Recent posts