E D R , A S I H C RSS

Signature Survey



HTML Template 부분을 Generating 하는 부분을 하던중, 디자이너가 툴로 만든 HTML 코드를 분석해볼때 SigntureSurvey 의 방법을 적용해보면 어떤 일이 일어날까 의문이 들었다. 그래서 간단하게 실험해보고, 어떠한 View 를 얻을 수 있을까 구경해보다.
Plex 사용.
~cpp 
from Plex import *
import StringIO

class HtmlSigSurveyer(Scanner):
    def repl_tagEnd(self, aText):
        self.begin('')
        result = "." * (len(aText)-1) + ">"+ str(len(aText)-1) +"\n"
        return  result
    def repl_tagChar(self, aText):
        return "."
    def repl_normalString(self, aText):
        return aText
    def repl_tagStart(self, aText):
        self.begin('tag')
        return aText
    def repl_enter(self, aText):
        return "\n"
    def repl_whiteSpace(self, aText):
        return ""

    tagStart = Str("<")
    tagEnd = Rep1(AnyBut(">")) + Str(">")
    enterCode = Str("\n")
    whiteSpace = Rep1(Str(" ")) | Rep1(Str("\t"))

    lexicon = Lexicon([
        (tagStart, repl_tagStart),
        State('tag', [
            (tagEnd, repl_tagEnd),
            (enterCode, repl_enter),
            (AnyChar, repl_tagChar)
        ]),
        (whiteSpace, repl_whiteSpace),
        (AnyChar, repl_normalString),
        ])

    def __init__(self, aStream):
        Scanner.__init__(self, self.lexicon, aStream)

    def process(self):
        writer = StringIO.StringIO("")
        while True:
            token = self.read()
            if token[0] is None:
                break
            writer.write(token[0])
        return writer.getvalue()

def readFromFile(aFileName):
    f = open(aFileName, 'r')
    text = f.read()
    f.close()
    return text
def writeToFile(aFileName, aStr):
    f = open(aFileName, 'w')
    f.write(aStr)
    f.close()

if __name__=="__main__":
    data = readFromFile("sig.html")
    surveyer = HtmlSigSurveyer(StringIO.StringIO(data))
    result = surveyer.process()
    lines = [line for line in result.splitlines() if line.strip() != '']
    count = 1
    for line in lines:
        print count, line
        count +=1

결과물이 대강 다음과 같았는데.
~cpp 
1 <............................................................>60
2 <..>2
3 <..........................>26
4 <...>3
5 <...>3
6 <..>2
7 <.........................>25
8 <..........................................................................>74
9 <...>3
10 <................................>32
11 <..........................................................................>74
12 <..>2
13 <..>2
14 <...............................................................................................>95
15 <.................................................>49
16 TV<..>2
17 &nbsp;&nbsp;&nbsp;<...............................................................................................>95
18 <.................................................>49
19 VTR<..>2
20 &nbsp;&nbsp;<...............................................................................................>95
21 <.................................................>49
22 DVD<..>2
23 &nbsp;&nbsp;&nbsp;<...............................................................................................>95
24 <.................................................>49
25 홈시어터<..>2
26 &nbsp;&nbsp;&nbsp;<...............................................................................................>95
27 <.................................................>49
28 냉장고<..>2
29 &nbsp;&nbsp;&nbsp;<...............................................................................................>95
30 <.................................................>49
31 세탁기<..>2
32 &nbsp;&nbsp;&nbsp;<...............................................................................................>95
33 <.................................................>49
34 오디오<..>2
35 &nbsp;&nbsp;&nbsp;<...............................................................................................>95
36 <.................................................>49
37 카세트<..>2
38 &nbsp;&nbsp;&nbsp;<...............................................................................................>95
39 <.................................................>49
40 워크맨/녹음기<..>2
41 <..>2
42 <.......................>23
43 <..............................................................................................>94
44 <...............................................................................................>95
45 <..>2
46 <.....................................................>53
47 <.............................................................>61
.
.
.
이를 분석할때는 4-5point 로 레이저로 2단 나누어서 찍었다. 별로 종이를 많이 차지하지 않는다.
정확히 분석을 한 것은 아니지만. <> 태그 안으로 쓴 글자수가 같다면 화면상에서도 비슷한 것을 보이게 하기 위해 C & P 를 했을 확률이 높다. 그러면 그 부분에 대해서 looping 을 하는 식으로 묶으면 될것 같다. 종이로 찍어놓고 보면 반복되는 부분에 대해서 일반화된 패턴이 보인다는 것을 알 수 있다. 그 부분에 대해 적절히 1차적으로 검색을 하고, generating 할때의 단위들을 끄집어내면 되는 것이다.

처음써봐서 완벽하게 확신이 들진 않지만, SignatureSurvey 를 사용하면 Duplication Code 를 찾는 방법으로 일반화를 시킬 수 있지 않을까 하는 상상을 해본다.
--1002
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:01
Processing time 0.0114 sec