Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2e33982
Testing Travis ci
AnoXDD Feb 2, 2017
ec5e05c
Update .travis.yml to (try to) get travis work
AnoXDD Feb 2, 2017
eeac626
Another try to get travis work
AnoXDD Feb 2, 2017
b3ee436
Maybe removing sudo will work
AnoXDD Feb 2, 2017
3d59fc6
Modifying the path of the phantomjs runner
AnoXDD Feb 2, 2017
15f939b
Pushing a commit that is supposed to be failing
AnoXDD Feb 2, 2017
ea78384
Trying to figure out why travis didn't find test_runner
AnoXDD Feb 2, 2017
80ca438
Adding the file that is missing ....
AnoXDD Feb 2, 2017
c69e34a
This commit is supposed to pass all the tests
AnoXDD Feb 2, 2017
cb7fd2f
Start working on migrating tests
AnoXDD Feb 2, 2017
6f553ff
This commit should fail all the tests
AnoXDD Feb 7, 2017
46c4991
Trying to figure out why Travis prints that error
AnoXDD Feb 7, 2017
449062d
Add missing library files
AnoXDD Feb 7, 2017
53df27a
Test another error
AnoXDD Feb 7, 2017
ba615ab
Another commit, just to know the error message
AnoXDD Feb 7, 2017
5644202
Another error push
AnoXDD Feb 7, 2017
b6b3c86
Let's see this error push
AnoXDD Feb 7, 2017
845e4f2
Sorry, this error push
AnoXDD Feb 7, 2017
a099fc8
Finishing the test suites
AnoXDD Feb 7, 2017
32b5af3
Add more test cases
AnoXDD Feb 7, 2017
a7009e0
Add more test cases (2nd try)
AnoXDD Feb 7, 2017
c9b665c
Add more test cases (3rd try)
AnoXDD Feb 7, 2017
bef95c0
Add more test cases (3rd try)
AnoXDD Feb 7, 2017
3f3c7e3
Add more test cases (3rd try)
AnoXDD Feb 7, 2017
9dc8238
Add more test cases (4th try)
AnoXDD Feb 8, 2017
cc5bc68
Fixed a bug in the test script
AnoXDD Feb 8, 2017
c60a5d8
Add more test cases (5th try)
AnoXDD Feb 9, 2017
2069011
Merge branch 'master' of https://github.com/AnoXDD/YPet
AnoXDD Feb 9, 2017
0b93119
Add more test cases (6th try)
AnoXDD Feb 9, 2017
cfcf239
Add more test cases (7th try)
AnoXDD Feb 9, 2017
993552d
Fixed a fatal bug that would cause the tester to drag from an undefin…
AnoXDD Feb 9, 2017
f2313f7
JAVASCRIPT USES INT INSTEAD OF BOOL IN COMPARATOR
AnoXDD Feb 9, 2017
61dbe60
Update README.md
AnoXDD Feb 9, 2017
bbb14cc
Deliberately break it to see what will happen
AnoXDD Feb 9, 2017
9770f63
Deliberately break it to see what will happen (this one is real)
AnoXDD Feb 9, 2017
d5e2076
Updated README and 'fix' the bug
AnoXDD Feb 9, 2017
07de783
Multiple test suites(html) supported
AnoXDD Feb 14, 2017
892e67f
Added tests for special chars and fixed test case
AnoXDD Feb 21, 2017
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
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js
node_js:
- "6.1"

before_script:
- npm install phantomjs

script:
- phantomjs runner_test.js
64 changes: 62 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# YPet

[![Build Status](https://travis-ci.org/AnoXDD/YPet.svg?branch=master)](https://travis-ci.org/AnoXDD/YPet)

[YPet](https://github.com/SuLab/YPet) is a Javascript library built in [Marionette.js](http://marionettejs.com/) to rapidly annotate paragraphs of text on websites. The project aims to rethink HTML text annotation, primarily focused on biocuration and adheres to the following rules:

* Limit the possibility for damaged annotations, individual letters are not desired.
Expand All @@ -17,8 +19,49 @@ Example of behavior:

## How to Use

The latest version of YPet (`ypet-new.js`) is built based on Marionette V3, but a older version of YPet (`ypet.js`) supports V2.

The build badge at the beginning of this file indicates the status of the **latest** version.

We recommend working with Marionette V3, because the older version of YPet does not process special characters like &, <, > properly. You will get `&amp;`, `&lt;`, `&gt;` instead of the characters.

### Setup

For Marionette V3:

```javascript
/* Setup the paragraphs with a string to tokenize */
var p1 = new Paragraph({'text': $('p#some-paragraph').html()});
var p2 = new Paragraph({'text': 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tincidunt tempus lorem, quis sollicitudin lectus pretium nec. Ut non enim.'});

/* Configure the # and colors of Annotation types (minimum 1 required) */
YPet.AnnotationTypes = new AnnotationTypeList([
{name: 'Person', color: '#A4DEAB'},
{name: 'Place', color: 'PowderBlue'},
{name: 'Thing', color: 'rgb(0, 180, 200)'}
]);

YPet = new Backbone.Marionette.Application({
region: "#doc" // where p1 and p2 are placed
});

/* Assign views to Region */
YPet.showView(new (Mn.View.extend({
el: ".container-to-hold-p1p2",
regions: {
'p1': '#container-to-place-p1',
'p2': '#container-to-place-p2'
}
}))());

/* Put the new Annotation views on the page */
YPet.getView().getRegion(1).show( new WordCollectionView({collection: p1.get('words')}) );
YPet.getView().getRegion(2).show( new WordCollectionView({collection: p2.get('words')}) );

YPet.start();
```
For Marionette V2:

```javascript
YPet.addInitializer(function(options) {
/* Setup the paragraphs with a string to tokenize */
Expand Down Expand Up @@ -47,12 +90,29 @@ YPet.start();

```

### Events
#### Events

If you want to live track annotations as they're put on the paragraph (to save, send to a server, or do something else with) the following callbacks and serialization methods are available.

Each annotation is returned as an object with a `start` and `text` attribute, as well as an array of children words.

For Marionette V3:

```javascript
YPet.getView().getRegion(1).currentView.collection.parentDocument.get('annotations').on('add', function(model, collection) {
console.log('Add:', model.toJSON(), collection.toJSON());
});

YPet.getView().getRegion(1).currentView.collection.parentDocument.get('annotations').on('remove', function(model, collection) {
console.log('Remove:', model.toJSON(), collection.toJSON());
});

YPet.getView().getRegion(1).currentView.collection.parentDocument.get('annotations').on('change', function(model) {
console.log('Change:', model.toJSON());
});
```

For Marionette V2:

```javascript
YPet['p1'].currentView.collection.parentDocument.get('annotations').on('add', function(model, collection) {
Expand All @@ -70,7 +130,7 @@ YPet['p1'].currentView.collection.parentDocument.get('annotations').on('change',

## About

[YPet](https://github.com/SuLab/YPet) was developed to rapidly annotate bio-medical literature for [Mark2Cure](http://mark2cure.org) at [The Su Lab](http://sulab.org/) by [Max Nanis](http://twitter.com/x0xMaximus).
[YPet](https://github.com/SuLab/YPet) was developed to rapidly annotate bio-medical literature for [Mark2Cure](http://mark2cure.org) at [The Su Lab](http://sulab.org/) by [Max Nanis](http://twitter.com/x0xMaximus). The testing script is written by [Runjie Guan](http://anoxic.me).


![The Scripps Research Institute](http://www.scripps.edu/files/images/logo120.png "The Scripps Research Institute")
Expand Down
96 changes: 96 additions & 0 deletions runner_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* phantomjs page setup */

var page = require('webpage').create();

page.onConsoleMessage = function(msg) {
console.log(msg);
};

page.viewportSize = {
width: 800,
height: 800
};

var test_suites = {
"./test/test_page.html": [
"_testClickOnValidWords",
"_testClickOnInvalidWords",

"_testDragSameLine",
"_testDragDifferentLine",
"_testDragOverSelectedWord",
"_testDragFromSelectedWord",
"_testDragToSelectedWord",

"_testDragInvalidWord",
"_testSubmitResults"
],
"./test/test_page_special_char.html": [
"_testClickOnInvalidWords",

"_testSelectAll",
"_testClickOnEachValidWord",
],
"./test/test_page_fixed.html": [
"_testClickOnValidWordsFixed",

"_testDragFixed",
"_testDragSelectedFixed",

"_testDragInvalidWordFixed"
]
};

/* test runner */
var htmls = Object.keys(test_suites);
var running_html = "";
for (var i = 0; i < htmls.length; ++i) {
(function(i) {
var interval = setInterval(function() {
if (running_html === htmls[i]) {
clearInterval(interval);
page.open(running_html, function(status) {
if (status !== "success") {
console.log("Error loading page");
phantom.exit(1);
} else {
console.log("\n===========Page loaded: " + running_html + "===========");
}

page.evaluate(function() {
return document.testInit();
});

test_suites[running_html].forEach(function(test_function) {
var msg = page.evaluate("document." + test_function);
if (msg && msg != "") {
throw new Error("Error: " + msg);
}
});

console.log(test_suites[running_html].length + " tests PASSED");
// Pass to the next test suite
if (!(running_html = htmls[++i])) {
phantom.exit(0);
}
});

}
}, 1000);
})(i);
}
running_html = htmls[0];


page.onError = function(msg, trace) {
console.error("An error occured");
console.error(JSON.stringify(trace));
/* inject a line number into the error message raised by assert() */
if (trace.length > 1) {
console.log(msg.replace(/: in /,
" in line " + (parseInt(trace[1].line) - 1) + " of "));
} else {
console.log("line " + (parseInt(trace[0].line) - 1) + ": " + msg);
}
phantom.exit(1);
};
11 changes: 11 additions & 0 deletions src/backbone.marionette_v3.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ YPet.addInitializer(function(options) {
});

YPet.start();

2 changes: 2 additions & 0 deletions src/lib/backbone-min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/lib/backbone.radio.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/lib/bootstrap.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/lib/jquery-1.11.1.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/lib/underscore-min.js

Large diffs are not rendered by default.

Loading