R package for text generation from data
The so-called "Linguistic Descriptions of Complex Phenomena" (LDCP) is a methodology that allows us modeling complex phenomena. It is structured as an architecture with the next 2 main pipeline tasks: (1) interpreting input data, and (2) generating automatic text reports customized to the user needs. The rLDCP package contains a set of methods aimed at facilitating the development of LDCP systems. The rLDCP package main goal is increasing the visibility of and the accessibility to the results derived from this research line.
In this website, you can get supplementary material to the information included into the next paper:
P. Conde-Clemente, Jose M. Alonso, G. Trivino. "rLDCP: R package for text generation form data". In Proceedings of the IEEE International Conference on Fuzzy Systems (FUZZ-IEEE), Naples, Italy, 2017 (DOI:10.1109/FUZZ-IEEE.2017.8015487).
The latest version of the package is available at Downloads.
This section provides you with instructions for installing the rLDCP package and running the example "ComfortableRoom" which is described in the paper.
Here you can download a file with all instructions given in the section.
The latest version of the package is in the Downloads tab. The binaries are currently only available for Windows. You should compile the source package for other operating systems.
First of all, the user has to download the package, and then its installation is as follows (Please, note that working with absolute path is required):
> install.packages('C:\\Downloads\\rLDCP_1.0.2.zip',repos=NULL)
package ‘rLDCP’ successfully unpacked and MD5 sums checked
Also, the user can install the package with RStudio. In the RStudio menu the user must select Tools and then Install Packages.... As result, the next popup window is open. The user must: (1) select that the package is installed from Package Archive File (.zip; .tar.gz); (2) select the package path C:/Downloads/rLDCP_1.0.2.zip; and (3) give a directory to install the library or just go on with the default installation directory.
Installing the rLDCP package from RStudio.
Then, the user has to import the XML package from the CRAN. This task can be accomplished as follows:
Using the install.packages method:
> install.packages("XML")
package ‘XML’ successfully unpacked and MD5 sums checked
Or using the RStudio wizard tool:
Installing the XML package from RStudio.
In this case, the user must select: (1) that the package is installed from Repository (CRAN, CRANextra), (2) the package name XML and (3) the installation directory or just go on with the given default directory.
The rLDCP package contains an example called ComfortableRoom. This section explains how to run the example.
Firstly, the user must copy all the example files into a local directory. They are in the extdata
folder of the rLDCP package. To copy them into a working directory ".", the user can run the next code:
> current.folder <- system.file("extdata", package="rLDCP")
> local.folder <- "."
> list.of.files <- list.files(path = current.folder, full.names = TRUE)
> file.copy(list.of.files, local.folder)
[1] TRUE TRUE TRUE TRUE TRUE
As result, the user should get the next files:
comfortableroom.xml
contains the example ComfortableRoom defined in XML
language.comfortableroom-pdf-ext.xml
contains the extension that generates reports in PDF
format.comfortableroom-mf-ext.xml
contains the extension that defines new membership functions.report.Rnw
contains the report template in Sweave language.data.csv
contains the related input data ready to test the examples.From the viewpoint of beginners, we present the ComfortableRoom system in the XML
file comfortableroom.xml. After running the next code, the example ComfortableRoom will be fully accessible in R
language.
> library(rLDCP)
> input <- "comfortableroom.xml"
> output <-"comfortableroom.R"
> xml2rldcp(input,output)
The xml is valid
The code has been generated successfully
The first line is in charge of loading the rLDCP package.
The next two lines define two variables: input and output.
They correspond to the path of the input file (in XML
) and the output file (in R
).
Then, the xml2rldcp
function is in charge of: (1) taking as input the path to the XML
file, (2) validating the LDCP system, (3) generating the corresponding R
code, and (4) generating the related output file.
Then, everything is ready to run the ComfortableRoom example.
The result of running comfortableroom.R
with the input data contained in data.csv
should be as follows:
> source(output)
Input: c(temperature,light), c(30,750)
Output: The room is uncomfortable, because the temperature is hot and the light is high.
Input: c(temperature,light), c(20,750)
Output: The room is very comfortable, because the temperature is warm and the light is high.
Input: c(temperature,light), c(10,750)
Output: The room is uncomfortable, because the temperature is cold and the light is high.
Input: c(temperature,light), c(10,250)
Output: The room is uncomfortable, because the temperature is cold and the light is low.
Input: c(temperature,light), c(20,500)
Output: The room is comfortable, because the temperature is warm and the light is medium.
Input: c(temperature,light), c(30,900)
Output: The room is uncomfortable, because the temperature is hot and the light is high.
From the viewpoint of advanced users, we extend the previous example: using an external tool that allows to generate reports in PDF
format; and defining our own membership function methods.
We can run these extensions using the same function source
as follows:
> output_pdf_ext <-"comfortableroom-pdf-ext.R"
> source(output_pdf_ext)
> output_mf_ext <-"comfortableroom-mf-ext.R"
> source(output_mf_ext)
Both file extensions use the data.csv
as input data. The comfortableroom-pdf-ext.R
use the file report.Rnw
as a report template.
rLDCP package - latest version | |
---|---|
Version: | 1.0.2 |
Depends: | R (>= 3.3.1) |
Imports: | XML (>= 3.98-1.4), methods |
Suggests: | testthat |
Published: | 2017-11-10 |
Author: | Patricia Conde-Clemente [aut, cre], Jose M. Alonso [aut], Gracian Trivino [aut] |
Maintainer: | Patricia Conde-Clemente <patricia.condeclemente@gmail.com> |
Licence: | GPL (>= 2) |
NeedsCompilation: | no |
Reference manual: | rLDCP.pdf |
Package source: | rLDCP_1.0.2.tar.gz |
Windows binaries: | rLDCP_1.0.2.zip |
DEMO - Comfortable Room 2 | |
---|---|
Generating several PDFs for the example introduced in the Handbook tab. One PDF for each single sample in the dataset. | comfortableroom2.zip |
DEMO - In Profile Photo 2 | |
---|---|
Generating several PDFs for the example first introduced in the next conference paper: P. Conde-Clemente, Jose M. Alonso, Gracian Trivino, Interpretable fuzzy system allowing to be framed in a profile photo through linguistic expressions, 8th Conference of the European Society for Fuzzy Logic and Technology (EUSFLAT 2013), Milan, Italia, pp. 463-468, 2013 (doi:10.2991/eusflat.2013.70) | inprofilephoto2.zip |