I need to create a java function that highlights a search result changing the color depending on the value of the attribute of the XML element.
XML element exemple:
<tok id="w-9" pos="NP" lemma="University">University</tok> The "pos" attribute has different values, for instance:
- NN
- NNS
- NP
- NPS
- JJ
- JJR
- JJS
- RB
- RBR
- RBS
- etc...
So the desired behavior would be:
- if the hit has value N* at pos attribute, highlight color is #992200
- if the hit has value JJ* at pos attribute, highlight color is #FFBB00
- if the hit has value RB* at pos attribute, highlight color is #FFCC11
In this moment, I do the search on the XML file and a java function highlights the hit but always with the same color and based on the id value:
Current function:
function highlight ( id, color ) { if ( !id ) { return -1; }; if ( document.getElementById(id) ) { var element = document.getElementById(id); // Move up to TOK when we are trying to highlight a DTOK if ( element.parentNode.tagName == "TOK" ) { element = element.parentNode; color = '#00ffff'; }; if ( element.parentNode.parentNode.tagName == "TOK" ) { element = element.parentNode.parentNode; color = '#00ffff'; }; element.style['background-color'] = color; element.style.backgroundColor= color; }; }; I'm not sure, but more or less the function should be something like:
function highlightpos (id) { // determine color if ( …N* ) color = "#992200"; ... }; where the check for N* should be something like
element.getAttribute('pos').substr(0,2) == "N*" The element.parentNode.tagName is only there because sometimes you get a dtok, which does not show in and by itself, only the tok is part of shows…
Thanks
No comments:
Post a Comment