|
Convert an HTML Text to a Prolog ListWritten by Yasuhisa Matsumura The program "HTML-to-List" reads an HTML text, converts it to a Prolog list, and then writes the list into a file. How to Use the Program?Click . Thanks to the PDCThe program uses Editor and Configuration programs developed by the PDC. The Editor is used only for displaying texts on the screen. The "Html to List" conversion is performed in the background. DomainsThe domains used are as follows: domains
str = s(string); t(string).
str_list = str*.
attribute = a(string,string).
attribute_list = attribute*.
struc = t(string, attribute_list, html);
s(string); c(string);
e(string,attribute_list); x(string, attribute_list);
ot(string, attribute_list); ct(string).
html = struc*.
Conversion Example<html>
<HEAD>
</HEAD>
<body bgcolor="blue">
Hi! How are you? <br>
This is Yasu Matsumura.<br>
<!-- This is a comment line -->
<XmlEmptyTag />
</body>
</html>
The above HTML text is converted to the following Prolog list: [t("html",[],
[t("head",[],
[]
),
t("body",[a("bgcolor","blue")],
[s("Hi! How are you?"),
e("br",[]),
s("This is Yasuihsa Matsumura"),
c("!-- This is a comment line--"),
x("xmlemptytag",[])
]
)
]
)
]
Additional ExplanationsThe temporary domains that are used only in the conversion process are: str= s(string); t(string), str_list = str*, ot(string, attribute_list) and ct(string). They are not included in the resultant domain html. Therefore, the list domain html is composed of: attribute = a(string,string). attribute_list = attribute*. struc = t(string, attribute_list, html); s(string); c(string); e(string,attribute_list); x(string, attribute_list). html = struc*. The abbreviations t, s, c, etc., stand for:
The program:
The resulting file "index.phtml" includes only one list. The list can be read as follows:domains
attribute = a(string,string).
attribute_list = attribute*.
struc = t(string, attribute_list, html);
s(string); c(string);
e(string,attribute_list); x(string, attribute_list).
html = struc*.
predicates
read_list : (string FileName) -> html Html determ(i).
clauses
read_list(FileName) = Html :-
Input = inputStream_file::openFile(FileName),
hasDomain(html, Html),
Html = Input:read(),
Input:close().
|