tnsr2trp: sparse tensor to triples

Description Usage Arguments Value Author(s) See Also Examples

View source: R/RDF2Tensor.R

Description

convert a sparse tensor (e.g. created using getTensor) to set of triples.

Usage

1
tnsr2trp(tnsr)

Arguments

tnsr

a sparse tensor (e.g. created using getTensor)

Value

a matrix of three columns containing the triples

Author(s)

Abdelmoneim Amer Desouki

See Also

getTnsrijk getTensor

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
trp=rbind(
    cbind('Alex',  'loves', 'Don'),
    cbind('Alex',  'loves', 'Elly'),
    cbind('Alex',  'hates', 'Bob'),
    cbind('Don',   'loves', 'Alex'),
    cbind('Don',   'hates', 'Chris'),
    cbind('Chris', 'hates', 'Bob'),
    cbind('Bob',   'hates', 'Chris'),
    cbind('Elly',  'hates', 'Chris'),
    cbind('Elly',  'hates', 'Bob'),
    cbind('Elly',  'loves', 'Alex')
    )
######
# form tensor as a set of frontal slices (Predicate mode)
    tnsr=getTensor(trp)
    trp_=tnsr2trp(tnsr)
    #print(any(! paste(trp_[,1],trp_[,2],trp_[,3]) %in% paste(trp[,1],trp[,2],trp[,3])))
    #print(any(! paste(trp[,1],trp[,2],trp[,3]) %in% paste(trp_[,1],trp_[,2],trp_[,3])))

RDFTensor documentation built on Jan. 16, 2021, 5:19 p.m.