More Visual Prolog 7.3 Examples

 

Convert  an HTML Text to a Prolog List

Written 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 File | Open.

Thanks to the PDC

The 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.

Domains

The 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 Explanations

The 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:

  • t - tag,
  • s - string,
  • c - comment like <!-- comment -->,
  • e - empty tag,
  • x - xml empty tag like <xml_empty />,
  • ot - opening tag,
  • ct - closing tag.

The program:

  1. reads the file (e.g. index.html);
  2. converts it to a list;
  3. writes the list in the file "index.phtml".

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().

 

 

Download the project

 

Note

The example requires Visual Prolog 7.3 Commercial Edition.

 

If you use the Personal Edition, but need the  features supported only in the Commercial Edition, you are welcome to order the latest build of this Edition just now: Order!

 

Users of previous versions of Visual Prolog are welcome to upgrade to the current version of Visual Prolog  to use the latest versions of the Visual Prolog examples.

 


Download VIP-ALC'08
Proceedings

Visual Prolog Application & Language Conference (VIP-ALC 2006) April 24-26 2006

Download VIP-ALC'06 Proceedings