Skip to content

Commit

Permalink
Merge pull request #83 from latin-language-toolkit/relation_plugin
Browse files Browse the repository at this point in the history
Relation plugin
  • Loading branch information
LFDM committed May 23, 2014
2 parents c4f9a7d + 8b40b61 commit 3eb4776
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 95 deletions.
3 changes: 3 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
<script src="./js/arethusa.hist/directives/history_undo.js"></script>
<script src="./js/arethusa.hist/directives/history_redo.js"></script>

<script src="./js/arethusa.relation.js"></script>
<script src="./js/arethusa.relation/relation.service.js"></script>

<script src="./js/arethusa.js"></script>
<script src="./js/services/text.js"></script>
<script src="./js/services/comment.js"></script>
Expand Down
9 changes: 4 additions & 5 deletions app/js/arethusa.core/directives/resizable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ angular.module('arethusa.core').directive('resizable', function($window, $docume
$document.on('mouseup', mouseup);
});


var mousemove = function(event) {
function mousemove(event) {
var x = event.pageX;
var el = element.parent();
var leftPos = el.position().left;
Expand All @@ -24,12 +23,12 @@ angular.module('arethusa.core').directive('resizable', function($window, $docume
var newSize = el.width() - diff;
el.width(newSize);
main.width(main.width() + diff);
};
}

var mouseup = function() {
function mouseup() {
$document.unbind('mousemove', mousemove);
$document.unbind('mouseup', mouseup);
};
}
}
};

Expand Down
9 changes: 9 additions & 0 deletions app/js/arethusa.dep_tree/directives/dependency_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ angular.module('arethusa.depTree').directive('dependencyTree', function($compile
render();
}
});
childScope.relation = token.relation;
childScope.$watch('relation.label', function(newVal, oldVal) {
// Very important to do here, otherwise the tree will
// be render a little often on startup...
if (newVal !== oldVal) {
updateEdge(token);
render();
}
});
});

scope.$watch('tokens', function(newVal, oldVal) {
Expand Down
3 changes: 2 additions & 1 deletion app/js/arethusa.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ angular.module(
'arethusa.morph',
'arethusa.depTree',
'arethusa.hist',
'arethusa.review'
'arethusa.review',
'arethusa.relation'
],
function($routeProvider, MAIN_ROUTE, CONF_ROUTE) {
$routeProvider.when('/', MAIN_ROUTE);
Expand Down
4 changes: 4 additions & 0 deletions app/js/arethusa.relation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";

angular.module('arethusa.relation', ['arethusa.core']);

51 changes: 51 additions & 0 deletions app/js/arethusa.relation/relation.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use strict";

angular.module('arethusa.relation').service('relation', function(state, configurator) {
var self = this;

this.conf = configurator.configurationFor('relation');
this.template = this.conf.template;
this.name = this.conf.name;
this.relationValues = this.conf.relations;
this.relations = {};

this.currentLabels = function() {
return arethusaUtil.inject({}, state.selectedTokens, function(memo, id, event) {
memo[id] = self.relations[id];
});
};

function splitLabel(relation) {
var split = relation.label.split('_');
relation.prefix = split[0];
relation.suffix = split[1];
}

this.buildLabel = function(relation) {
var elements = [relation.prefix, relation.suffix];
var clean = arethusaUtil.inject([], elements, function(memo, el) {
if (el) {
memo.push(el);
}
});
relation.label = clean.join('_');
};

this.expandRelation = function(relation) {
splitLabel(relation);
return relation;
};

this.createInternalState = function() {
return arethusaUtil.inject({}, state.tokens, function(memo, id, token) {
memo[id] = {
string: token.string,
relation: self.expandRelation(token.relation)
};
});
};

this.init = function() {
self.relations = self.createInternalState();
};
});
178 changes: 91 additions & 87 deletions app/static/configs/relation/relations.json
Original file line number Diff line number Diff line change
@@ -1,92 +1,96 @@
{
"relations" : {
"PRED" : {
"short" : "PRED",
"long" : "predicate"
},
"SBJ" : {
"short" : "SBJ",
"long" : "subject"
},
"OBJ" : {
"short" : "OBJ",
"long" : "object"
},
"ATR" : {
"short" : "ATR",
"long" : "attribute"
},
"ADV" : {
"short" : "ADV",
"long" : "adverbial"
},
"ATV" : {
"short" : "ATV",
"long" : "complement"
},
"AtvV" : {
"short" : "AtvV",
"long" : "complement"
},
"PNOM" : {
"short" : "PNOM",
"long" : "predicate nominal"
},
"OCCOMP" : {
"short" : "OCCOMP",
"long" : "object complement"
},
"COORD" : {
"short" : "COORD",
"long" : "coordinator"
},
"CO" : {
"short" : "CO",
"long" : "coordinated"
},
"APOS" : {
"short" : "APOS",
"long" : "apposing element"
},
"AuxP" : {
"short" : "AuxP",
"long" : "preposition"
},
"AuxC" : {
"short" : "AuxC",
"long" : "conjunction"
},
"AuxR" : {
"short" : "AuxR",
"long" : "reflexive passive"
},
"AuxV" : {
"short" : "AuxV",
"long" : "auxiliary verb"
},
"AuxX" : {
"short" : "AuxX",
"long" : "comma"
},
"AuxG" : {
"short" : "AuxG",
"long" : "bracketing punctuation"
},
"AuxK" : {
"short" : "AuxK",
"long" : "terminal punctuation"
},
"AuxY" : {
"short" : "AuxY",
"long" : "sentence adverbial"
},
"AuxZ" : {
"short" : "AuxZ",
"long" : "emphasizing particle"
},
"ExD" : {
"short" : "ExD",
"long" : "ellipsis"
"labels" : {
"PRED" : {
"short" : "PRED",
"long" : "predicate"
},
"SBJ" : {
"short" : "SBJ",
"long" : "subject"
},
"OBJ" : {
"short" : "OBJ",
"long" : "object"
},
"ATR" : {
"short" : "ATR",
"long" : "attribute"
},
"ADV" : {
"short" : "ADV",
"long" : "adverbial"
},
"ATV" : {
"short" : "ATV",
"long" : "complement"
},
"AtvV" : {
"short" : "AtvV",
"long" : "complement"
},
"PNOM" : {
"short" : "PNOM",
"long" : "predicate nominal"
},
"OCCOMP" : {
"short" : "OCCOMP",
"long" : "object complement"
},
"COORD" : {
"short" : "COORD",
"long" : "coordinator"
},
"APOS" : {
"short" : "APOS",
"long" : "apposing element"
},
"AuxP" : {
"short" : "AuxP",
"long" : "preposition"
},
"AuxC" : {
"short" : "AuxC",
"long" : "conjunction"
},
"AuxR" : {
"short" : "AuxR",
"long" : "reflexive passive"
},
"AuxV" : {
"short" : "AuxV",
"long" : "auxiliary verb"
},
"AuxX" : {
"short" : "AuxX",
"long" : "comma"
},
"AuxG" : {
"short" : "AuxG",
"long" : "bracketing punctuation"
},
"AuxK" : {
"short" : "AuxK",
"long" : "terminal punctuation"
},
"AuxY" : {
"short" : "AuxY",
"long" : "sentence adverbial"
},
"AuxZ" : {
"short" : "AuxZ",
"long" : "emphasizing particle"
},
"ExD" : {
"short" : "ExD",
"long" : "ellipsis"
}
},
"suffixes" : {
"CO" : {
"short" : "CO",
"long" : "coordinated"
}
}
}
}
7 changes: 7 additions & 0 deletions app/static/configs/staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"text",
"depTree",
"morph",
"relation",
"history",
"external_history",
"comment"
Expand Down Expand Up @@ -56,6 +57,12 @@
"fileUrl" : "./static/configs/morph/attributes.json"
},

"relation" : {
"name" : "relation",
"template" : "templates/relation.html",
"fileUrl" : "./static/configs/relation/relations.json"
},

"history" : {
"name" : "history",
"listener" : true,
Expand Down
7 changes: 7 additions & 0 deletions app/static/configs/staging2.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"plugins" : [
"text",
"depTree",
"relation",
"review",
"morph",
"history",
Expand Down Expand Up @@ -70,6 +71,12 @@
"fileUrl" : "./static/configs/morph/attributes.json"
},

"relation" : {
"name" : "relation",
"template" : "templates/relation.html",
"fileUrl" : "./static/configs/relation/relations.json"
},

"review" : {
"name" : "review",
"template" : "templates/arethusa.review/review.html",
Expand Down
4 changes: 2 additions & 2 deletions app/templates/main_with_sidepanel.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@


<div class="row panel full-height">
<div id="main-body" class="columns small-8">
<div id="main-body" class="columns small-7">
<div ng-repeat="pl in mainPlugins">
<plugin name="pl"/>
</div>
</div>

<div id="sidepanel" class="columns small-4">
<div id="sidepanel" class="columns small-5">
<div id="sidepanel-resizer" class="full-height" resizable></div>
<div id="sidepanel-body">
<tabset>
Expand Down
21 changes: 21 additions & 0 deletions app/templates/relation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div ng-repeat="(id, obj) in plugin.currentLabels()">
<p>{{ obj.string }}</p>
<div class="small-3 columns">
<select
ng-model="obj.relation.prefix"
ng-options="name as value.short for (name, value) in plugin.relationValues.labels"
ng-change="plugin.buildLabel(obj.relation)"
ng-init="obj.relation.prefix">
<option value=""></option>
</select>
</div>
<div class="small-2 columns left">
<select
ng-model="obj.relation.suffix"
ng-options="name as value.short for (name, value) in plugin.relationValues.suffixes"
ng-change="plugin.buildLabel(obj.relation)"
ng-init="obj.relation.suffix">
<option value=""></option>
</select>
</div>
</div>

0 comments on commit 3eb4776

Please sign in to comment.