kstIO

Cord Hockemeyer

Version 0.6-0

Content

Introduction

The current functionality of kstIO stems from two developmental processes:

File formats

Classical ASCII file formats

The aforementioned binary file formats are not (and probably never will be) supported by kstIO. The ASCII formats are fully supported; they come in three different forms, each expanding the previous one by additional header lines containing meta information.

Spreadsheet formats

The more recent spreadsheet formats comprise three types: CSV (comma-separated values), ODS (Open Document Spreadsheet, e.g. by LibreOffice or OpenOffice), and XLSX (Microsoft Excel). All kstIO I/O functions support all three spreadsheet types.

The spreadsheet tables have the same form in all three formats (CSV, ODS, and XHTML). They typically (exceptions are, e.g., surmise functions; see below) start with a header line containing the item names followed by the binary matrix as described above for the ASCII files. Surmise and attribution functions have an additional preceding column containing the name of the item for which the respective matrix row describes a clause.

Supported data structures

Both basic KST packages, kst and kstMatrix, use hierarchies of R classes. Class names in kst start with a ‘k’, those in kstmatrix with a ‘km’. In principle, if an object belongs to some class, the kst and kstMatrix functions assume that it fulfills the conditions of that class.

kstMatrix classes

The subsequent figure (from the kstMatrix vignette) shows the class hierarchy in that package. It means, e.g., that kmqspace is a sub-class of kmspace which is a sub-class of kmstructure which again is a sub-class of kmfamset.

Figure 1: kstMatrixclass hierarchy

List of kstMatrix classes

kst classes

The class hierarchy of kst is very similar, basically it is a subset because some functionality (and therefore several classes) have been developed (or defined, respectively) in kstMatrix only. While kstMatrix class-names start with ‘km’, the kst class-names start with a simple ‘k’.


Figure 2: kst class hierarchy

Functionality and default parameters

For most of the data types shown in Figures 1 & 2, there are reading and writing functions as listed below. Exceptions to this are quasi–ordinal knowledge spaces (kmqspace class) and neighbourhoods (kmneighbourhood class).

Function list

Reading functions

1These functions return a list with two elements, matrix and sets, containing the loaded data in the respective form. 2These functions return the respective data as kstMatrix class object as there is no corresponding kst class.

Writing functions

These functions accept kst and kstMatrix data objects.

One might consider to integrate the write functions into one S3 class. However, for technical reasons this would not work for the read functions.

Utilities

There are two utility functions mapping between set and matrix representations. These functions do not respect the classes assigned to the objects which are to be mapped.

Function parameters

There are numerous parameters shared by most of the reading and writing functions.

Mandatory parameters

Optional parameters

Please note that not all optional parameters are supported by all functions. For example, there are no properties to be enforced with kmdata objects.

Examples

For the following examples, we use the xpl basis from the kstMatrix package just because the object and the resulting files are small.

Setup

We start with some setup: importing libraries and defining filenames:

library(kstIO)
#> Loading required package: sets
#> Loading required package: kstMatrix
#> Loading required package: openxlsx2
#> Loading required package: readODS
#> Loading required package: tools
library(kstMatrix)
csvname <- paste0(tempdir(), "/xpl_bas.csv")
odsname <- paste0(tempdir(), "/xpl_bas.ods")
srbtname <- paste0(tempdir(), "/xpl.bas")

The xpl basis looks like this:

xpl$basis
a b c d
1 0 0 0
0 1 0 0
1 0 1 0
0 1 1 0
1 1 0 1

Spreadsheet files

First, we write the basis to a CSV file and print that file:

write_kbase(xpl$basis, csvname)
cat(readLines(csvname), sep='\n')
"a","b","c","d"
1,0,0,0
0,1,0,0
1,0,1,0
0,1,1,0
1,1,0,1

Next, we write it to an ODS file and show a screenshot of that file opened in LibreOffice.

write_kbase(xpl$basis, odsname)
odsname
[1] "/tmp/RtmpOFTD0Y/xpl_bas.ods"


Figure 3: LibreOffice Screenshot with saved ODS format basis file

In the next step, we read the ODS file.

read_kbase(paste0(tempdir(), "/xpl_bas.ods"))
$matrix
     a b c d
[1,] 1 0 0 0
[2,] 0 1 0 0
[3,] 1 0 1 0
[4,] 0 1 1 0
[5,] 1 1 0 1
attr(,"class")
[1] "kmbasis"  "kmfamset" "matrix"   "array"   

$sets
{{"a"}, {"b"}, {"a", "c"}, {"b", "c"}, {"a", "b", "d"}}

ASCII file

Finally, we write a classical ASCII file in SRBT format and print the file contents.

write_kbase(xpl$basis, srbtname, format="SRBT")
cat(readLines(srbtname), sep='\n')
#SRBT v2.0 basis
4
5
1000
0100
1010
0110
1101