Skip to content

Commit 477cdc6

Browse files
committed
dp : links
1 parent 9a34f5b commit 477cdc6

File tree

7 files changed

+26
-74
lines changed

7 files changed

+26
-74
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: diffrprojects
22
Title: Using diffr for more than two files
33
Date: 2016-08-01
4-
Version: 0.1.1.90000
4+
Version: 0.1.2.90000
55
Authors@R: c(
66
person(
77
"Peter", "Meissner",

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export(modus)
1313
export(rbind_fill)
1414
export(seq_dim1)
1515
export(shift)
16-
export(which_token)
1716
import(hellno)
1817
import(rtext)
1918
import(stringb)

R/diffrproject.R

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ diffrproject <-
3636
meta = list(),
3737
options = list(),
3838
tracks = list(),
39+
links = list(),
3940
linkage = list(),
40-
texts_connected = list(),
4141
distance = list(),
4242
texts = list(),
4343

@@ -47,18 +47,7 @@ diffrproject <-
4747
text_add = function( rtext, name = NULL ){
4848

4949
# input check
50-
stopifnot("rtext" %in% class(rtext))
51-
52-
# connecting text with other text
53-
if( length(self$texts)>0 ){
54-
next_item <- length(self$texts_connected)+1
55-
last_item <- length(self$texts)
56-
self$texts_connected[[next_item]] <-
57-
list(
58-
self$texts[[last_item]],
59-
rtext
60-
)
61-
}
50+
stopifnot("rtext" %in% class(rtext) )
6251

6352
# working variable creation
6453
names <- names(self$texts)
@@ -101,6 +90,21 @@ diffrproject <-
10190
dp_text_base_data(self)
10291
},
10392

93+
texts_link = function(from=NULL, to=NULL, delete=FALSE){
94+
from <- names(self$texts[from])
95+
to <- names(self$texts[to])
96+
linker <- function(from, to, delete){
97+
name <- text_c(from, "_", to)
98+
if(delete){
99+
self$links[name] <- NULL
100+
}else{
101+
self$links[[name]] <- list(from=from, to=to)
102+
}
103+
}
104+
mapply(linker, from, to, delete=delete)
105+
invisible(self)
106+
},
107+
104108
# universal getter
105109
get = function(name){
106110
if(name=="private"){

R/tools.R

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -173,27 +173,6 @@ seq_dim1 <- function(x){
173173
}
174174

175175

176-
#' function returning index of spans that entail x
177-
#' @param x position of the character
178-
#' @param y1 start position of the token
179-
#' @param y2 end position of the token
180-
#' @export
181-
which_token <- function(x, y1, y2){
182-
# how to order x and y?
183-
order_x <- order(x)
184-
order_y <- order(y1)
185-
# order x and y! - which_token_worker expects inputs to be ordered
186-
ordered_x <- x[order_x]
187-
ordered_y1 <- y1[order_y]
188-
ordered_y2 <- y2[order_y]
189-
# doing-duty-to-do
190-
index <- which_token_worker(ordered_x, ordered_y1, ordered_y2)
191-
# ordering back to input ordering
192-
index <- order_y[index[order(order_x)]]
193-
# return
194-
index
195-
}
196-
197176

198177

199178

dev.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ dp$text_add(
2121
rtext$new(text_file=text_files[1], encoding="latin1")
2222
)
2323

24-
dp$texts
25-
2624
dp$text_add(
27-
rtext = rtext$new(text_file=text_files[1], encoding="latin1"),
25+
rtext = rtext$new(text_file=text_files[2], encoding="latin1"),
2826
name = basename(text_files[2])
2927
)
3028

29+
length(dp$texts)
30+
names(dp$texts)
31+
32+
dp$texts_link(1,2)
33+
dp$links
34+
35+
dp$texts_link(1,2, TRUE)
3136

3237
#### ---------------------------------------------------------------------------
3338

man/which_token.Rd

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/testthat/test_tools.r

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,3 @@ test_that("easy examples work properly", {
1313
)
1414

1515

16-
17-
context("tools which_token()")
18-
19-
test_that("easy examples work properly", {
20-
expect_true( which_token( x = 1, y1 = 1, y2 = 1 ) == 1 )
21-
expect_true( which_token( x = 2, y1 = c(2,1), y2 = c(2,1) ) == 1 )
22-
expect_true( which_token( x = 1, y1 = c(2,1), y2 = c(2,1) ) == 2 )
23-
expect_equal( which_token( x = 1:2, y1 = c(2,1), y2 = c(2,1) ), c(2,1) )
24-
expect_equal( which_token( x = c(7,2,4), y1 = c(1,3,7), y2 = c(2,6,2000) ), c(3,1,2) )
25-
expect_equal( which_token( x = 1:4, y1 = c(1,3,7), y2 = c(2,6,2000) ), c(1,1,2,2))
26-
expect_true( is.na(which_token( x = 2001, y1 = c(1,3,7), y2 = c(2,6,2000) )) )
27-
}
28-
)
29-
30-
31-

0 commit comments

Comments
 (0)