Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/0.2.1 #13

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### CHANGES IN recogito VERSION 0.2.1

- Allow multiple documents to be annotated with text in recogito to cleanly updated
- recogitoOutput gains the arguments refresh, annotationMode, tags, rtags
allowing text updates, annotationMode(RELATIONS,ANNOTATION), annotation tags,
and relations tags to be updated through the reactive component.

### CHANGES IN recogito VERSION 0.2.0

- read_annotorious now extracts from x$target$selector instead of x$target[[1]]$value
Expand Down
2 changes: 1 addition & 1 deletion R/annotorious.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ renderOpenSeaDragonNoToolbar <- function(expr, env = parent.frame(), quoted = FA
#' url <- paste("https://upload.wikimedia.org/",
#' "wikipedia/commons/a/a0/Pamphlet_dutch_tulipomania_1637.jpg",
#' sep = "")
#' url <- system.file(package = "recogito", "examples", "Pamphlet_dutch_tulipomania_1637.jpg")
#' url <- system.file(package = "recogito", "examples/annotorious", "Pamphlet_dutch_tulipomania_1637.jpg")
#' x <- '[
#' {
#' "type":"Annotation",
Expand Down
20 changes: 11 additions & 9 deletions R/recogito.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@
#' dependencies = tagsetcss)
#' x
recogito <- function(inputId = "annotations",
text,
text="",
type = c("relations", "tags"),
tags = c("Location", "Person", "Place", "Other"),
mode = c("html", "pre"),
annotations = "{}", width = NULL, height = NULL, elementId = NULL, dependencies = NULL) {
rtags= c("isLinked"),
refresh = FALSE,
annotationMode="ANNOTATION",
annotations="{}",
mode = c("html", "pre"), width = NULL, height = NULL, elementId = NULL, dependencies = NULL) {
type <- match.arg(type)
mode <- match.arg(mode)
x <- list(inputId = inputId, text = text, tags = tags, type = type,
#path = tempfile(pattern = "annotations_", fileext = ".json"),
mode = mode, annotations = annotations)
mode = mode, refresh = refresh, annotations = annotations, annotationMode = annotationMode)
if(type == "relations"){
htmlwidgets::createWidget(name = 'recogito', x,
width = width, height = height, package = 'recogito', elementId = elementId, dependencies = dependencies)
Expand All @@ -71,11 +73,9 @@ recogito <- function(inputId = "annotations",

widget_html.recogito <- function(id, style, class, ...){
el <- htmltools::tags$div(
id = sprintf("%s-outer-container", id), style = "position:relative;",
id = sprintf("%s-outer-container", id), style = "position:relative;",
htmltools::tags$div(
id = sprintf("%s-content", id), class = "plaintext", style = "max-width:920px;font-family:'Lato', sans-serif;font-size:17px;line-height:27px;",
htmltools::tags$button(id = sprintf("%s-toggle", id), "MODE: ANNOTATION"),
#tags$button(id = "toggle-mode", "MODE: ANNOTATION"),
htmltools::tags$hr(),
htmltools::tags$div(id = id, class = class)
)
Expand Down Expand Up @@ -170,8 +170,10 @@ widget_html.recogitotagsonly <- function(id, style, class, ...){
#'
#' recogitoOutput(outputId = "annotation_text")
#' recogitotagsonlyOutput(outputId = "annotation_text")
recogitoOutput <- function(outputId, width = '100%', height = '400px'){
recogitoOutput <- function(outputId, width = '100%', height = '400px',mode="html",tags=c("PERSON","TIME"),rtags=c("isLinked"),annotationMode="ANNOTATION"){
htmltools::tags$div(id = paste0(outputId,"-data"), `init-data`=jsonlite::toJSON(list(mode=mode,tags=tags,rtags=rtags)),
htmlwidgets::shinyWidgetOutput(outputId, name = 'recogito', width, height, package = 'recogito')
)
}


Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,43 @@ Look to documentation of the functions
help(package = "recogito")
```

### Testing
Two example applications are provided for recogito

- inst/examples/recogito
- inst/examples/recogitotagsonly

Before running the unit tests these two applications need to be running
on port 5447 and 5448

```
library(shiny)
library(devtools)
devtools::load_all()
appDir = system.file(package="recogito","examples/recogito")
runApp(appDir,port=5447L)
```

In another R session

```
library(shiny)
library(devtools)
devtools::load_all()
appDir = system.file(package="recogito","examples/recogitotagsonly")
runApp(appDir,port=5448L)
```

In a third R session with working directory in the recogito
package directory you can run the selenium tests

```
devtools::test()

```

See documentation from RSelenium for more details


### DIGI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ server <- function(input, output) {
read_annotorious(input$annotations)
})
}
shinyApp(ui, server)


if(FALSE){
Expand Down Expand Up @@ -44,3 +43,5 @@ if(FALSE){
image_crop(img, geometry_area(x = x$x, y = x$y, width = x$width, height = x$height))
image_crop(img, geometry_area(x = x$x, y = x$y, width = x$width, height = x$height))
}

shinyApp(ui, server)
File renamed without changes.
128 changes: 128 additions & 0 deletions inst/examples/recogito/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
txt <- "Josh went to the bakery in Brussels.\nWhat an adventure!"

library(shiny)
library(recogito)
txt <- "Tell me, O muse, of that ingenious hero who travelled far and wide after he had sacked
the famous town of Troy. Many cities did he visit, and many were the nations with whose manners and customs
he was acquainted; moreover he suffered much by sea while trying to save his own life and bring his men safely
home; but do what he might he could not save his men, for they perished through their own sheer folly in eating
the cattle of the Sun-god Hyperion; so the god prevented them from ever reaching home. Tell me, too, about all
these things, O daughter of Jove, from whatsoever source you may know them.\n
So now all who escaped death in battle or by shipwreck had got safely home except Ulysses,
and he, though he was longing to return to his wife and country, was detained by the goddess Calypso, who
had got him into a large cave and wanted to marry him. But as years went by, there came a time when the gods
settled that he should go back to Ithaca; even then, however, when he was among his own people, his troubles
were not yet over; nevertheless all the gods had now begun to pity him except Neptune, who still persecuted
him without ceasing and would not let him get home."

## Example Annotation
annotation <- '[
{
"type":"Annotation",
"body":[
{"type":"TextualBody","value":"sdfsd","purpose":"commenting"},
{"type":"TextualBody","value":"Person","purpose":"tagging"}],
"target":{"selector":[
{"type":"TextQuoteSelector","exact":"ngenious hero"},
{"type":"TextPositionSelector","start":42,"end":55}]},
"@context":"http://www.w3.org/ns/anno.jsonld",
"id":"#a4ea53d4-69f3-4392-a3dd-cbb7e9ad50cb"
},
{
"type":"Annotation",
"body":[{"type":"TextualBody","value":"Person","purpose":"tagging"},
{"type":"TextualBody","value":"Location","purpose":"tagging"}],
"target":{"selector":[{"type":"TextQuoteSelector","exact":"far and"},
{"type":"TextPositionSelector","start":70,"end":77}]},
"@context":"http://www.w3.org/ns/anno.jsonld",
"id":"#d7050196-2537-42bf-9d1b-a3f9e4c9fbc6"
}
]'


## Function to generate new text for annotation
getText <- function(){
text = letters[floor(runif(2000)*25+1)]
text[sample(1:2000,500)]=" "
text=paste(text,collapse="")
text
}

tagset <- c("LOCATION", "TIME", "PERSON")
rtagset <- c("subject", "related", "isLinked")
tagstyles <- "
.tag-PERSON {
color:red;
}
.tag-LOCATION {
background-color:green;
}
.tag-TIME {
font-weight: bold;
}
"

ui <- fluidPage(tags$head(tags$style(HTML(tagstyles))),
actionButton("nexttext","Next"),
actionButton("loadannotation","Load Annotation"),
actionButton("annotationmode","MODE: ANNOTATION"),
tags$br(),
recogitoOutput(outputId = "annotation_text",
mode="PRE",
tags=tagset,
rtags=rtagset,
annotationMode='ANNOTATION'
),
tags$hr(),
tags$h3("Results"),
verbatimTextOutput(outputId = "annotation_result"))

server <- function(input, output, session) {

mode <- reactiveValues(value = "ANNOTATION")

output$annotation_text <- renderRecogito({
recogito("annotations", text = txt, refresh=TRUE)
})

output$annotation_result <- renderPrint({
if(length(input$annotations) > 0){
x <- read_recogito(input$annotations)
x
}
})

## Load annotations onto existing text
observeEvent(input$loadannotation, {
output$annotation_text <- renderRecogito({
recogito("annotations", annotations = annotation,refresh=FALSE)
})
})

## Load New Text into Interface
observeEvent(input$nexttext, {
newText = getText()
output$annotation_text <- renderRecogito({
recogito("annotations", annotations = "{}", text = newText,refresh=TRUE)
})
})

## Change from annotation mode to relation mode
observeEvent(input$annotationmode, {
if(mode$value=="ANNOTATION"){
output$annotation_text <- renderRecogito({
recogito("annotations", refresh=FALSE, annotationMode="RELATIONS")
})
updateActionButton(session,"annotationmode",label="MODE: RELATIONS")
mode$value <- "RELATIONS"
}else{
output$annotation_text <- renderRecogito({
recogito("annotations", refresh=FALSE,annotationMode="ANNOTATION")
})
updateActionButton(session,"annotationmode",label="MODE: ANNOTATION")
mode$value <- "ANNOTATION"
}
})

}
shinyApp(ui, server)
3 changes: 3 additions & 0 deletions inst/examples/recogito/tests/shinytest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library(shinytest)
shinytest::testApp("../")

39 changes: 39 additions & 0 deletions inst/examples/recogito/tests/shinytest/tagging-expected/001.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"input": {
"annotationmode": 0,
"loadannotation": 0,
"nexttext": 0
},
"output": {
"annotation_result": "",
"annotation_text": {
"x": {
"inputId": "annotations",
"text": "Tell me, O muse, of that ingenious hero who travelled far and wide after he had sacked\nthe famous town of Troy. Many cities did he visit, and many were the nations with whose manners and customs\nhe was acquainted; moreover he suffered much by sea while trying to save his own life and bring his men safely\nhome; but do what he might he could not save his men, for they perished through their own sheer folly in eating\nthe cattle of the Sun-god Hyperion; so the god prevented them from ever reaching home. Tell me, too, about all\nthese things, O daughter of Jove, from whatsoever source you may know them.\n\nSo now all who escaped death in battle or by shipwreck had got safely home except Ulysses,\nand he, though he was longing to return to his wife and country, was detained by the goddess Calypso, who\nhad got him into a large cave and wanted to marry him. But as years went by, there came a time when the gods\nsettled that he should go back to Ithaca; even then, however, when he was among his own people, his troubles\nwere not yet over; nevertheless all the gods had now begun to pity him except Neptune, who still persecuted\nhim without ceasing and would not let him get home.",
"tags": [
"Location",
"Person",
"Place",
"Other"
],
"type": "relations",
"mode": "html",
"refresh": true,
"annotations": "{}",
"annotationMode": "ANNOTATION"
},
"evals": [

],
"jsHooks": [

],
"deps": [

]
}
},
"export": {

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions inst/examples/recogito/tests/shinytest/tagging.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
app <- ShinyDriver$new("../../")
app$snapshotInit("tagging")

app$snapshot()
3 changes: 3 additions & 0 deletions inst/examples/recogitotagsonly/tests/shinytest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library(shinytest)
shinytest::testApp("../")

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"input": {

},
"output": {
"annotation_result": "",
"annotation_text": {
"x": {
"inputId": "annotations",
"text": "Tell me, O muse, of that ingenious hero who travelled far and wide after he had sacked\nthe famous town of Troy. Many cities did he visit, and many were the nations with whose manners and customs\nhe was acquainted; moreover he suffered much by sea while trying to save his own life and bring his men safely\nhome; but do what he might he could not save his men, for they perished through their own sheer folly in eating\nthe cattle of the Sun-god Hyperion; so the god prevented them from ever reaching home. Tell me, too, about all\nthese things, O daughter of Jove, from whatsoever source you may know them.\n\nSo now all who escaped death in battle or by shipwreck had got safely home except Ulysses,\nand he, though he was longing to return to his wife and country, was detained by the goddess Calypso, who\nhad got him into a large cave and wanted to marry him. But as years went by, there came a time when the gods\nsettled that he should go back to Ithaca; even then, however, when he was among his own people, his troubles\nwere not yet over; nevertheless all the gods had now begun to pity him except Neptune, who still persecuted\nhim without ceasing and would not let him get home.",
"tags": [
"LOCATION",
"TIME",
"PERSON"
],
"type": "relations",
"mode": "html",
"refresh": false,
"annotations": "{}",
"annotationMode": "ANNOTATION"
},
"evals": [

],
"jsHooks": [

],
"deps": [

]
}
},
"export": {

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions inst/examples/recogitotagsonly/tests/shinytest/tagging.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
library("base")
app <- ShinyDriver$new("../../")
app$snapshotInit("tagging")

app$executeScript(
'
move = $.Event(\'mousemove\');
moveover = $.Event(\'mousemove\');
down = $.Event(\'mousedown\');
up = $.Event(\'mouseup\');

// coordinates
move.pageX = 100;
move.pageY = 100;
moveover.pageX = 300;
moveover.pageY = 100;

$(document).trigger(move);
$(document).trigger(down);
$(document).trigger(moveover);
$(document).trigger(up);
'
)
Sys.sleep(3)

app$snapshot()
Loading