Skip to content

Commit 5927a6f

Browse files
committed
Fixing the transform of the classified text into string with serialized spans for named entities
1 parent 95727f0 commit 5927a6f

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

src/main/js/frontend/src/App.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,15 @@ body {
5454
width: 100%;
5555
}
5656

57+
.i-misc {
58+
color: green;
59+
}
60+
61+
.i-per {
62+
color: red;
63+
}
64+
65+
.i-loc {
66+
color: blue;
67+
}
68+

src/main/js/frontend/src/NERContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function NERContext() {
104104
<Row>
105105
<div>Results</div>
106106
<hr/>
107-
<div>{namedEntities}</div>
107+
<div dangerouslySetInnerHTML={{__html: namedEntities}}></div>
108108
<div>{
109109
nerError.code ?
110110
<>

src/main/xar-resources/modules/rest-api.xqm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ declare
150150
function api:query-text-as-json($content as xs:string) as map(*) {
151151
let $postBody := fn:parse-json(util:base64-decode($content))
152152
let $properties := ner:properties-from-language($postBody?language)
153+
let $classified := ner:classify($postBody?text, $properties)
153154
return
154155
try {
155156
map {
156-
'text' : ner:stringify(ner:classify($postBody?text, $properties))
157+
'text' : ner:stringify($classified)
157158
}
158159
} catch * {
159160
map {

src/main/xquery/ner-module.xqm

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
2121
: @param $match The match text for a snippet that contains highlighted text
2222
: @return A string with highlight spans encoded within the string
2323
:)
24-
declare function ner:stringify($match as node()) as xs:string {
24+
declare function ner:stringify($match) as xs:string {
2525
fn:string-join(
26-
for $text-or-highlight in $match/node()
26+
for $text-or-highlight in $match
2727
return
2828
if ($text-or-highlight instance of element())
2929
then
@@ -97,18 +97,14 @@ function ner:classify-node($node as node(), $language as xs:string) as node() {
9797
:)
9898
declare
9999
function ner:properties-from-language($language as xs:string) as map(*) {
100-
try {
101-
switch ($language)
102-
case "en" return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-english.json")
103-
case "ar" return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-arabic.json")
104-
case "es" return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-spanish.json")
105-
case "fr" return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-french.json")
106-
case "zh" return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-chinese.json")
107-
case "de" return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-german.json")
108-
default return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-english.json")
109-
} catch * {
110-
fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-english.json")
111-
}
100+
switch ($language)
101+
case "en" return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-english.json")
102+
case "ar" return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-arabic.json")
103+
case "es" return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-spanish.json")
104+
case "fr" return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-french.json")
105+
case "zh" return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-chinese.json")
106+
case "de" return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-german.json")
107+
default return fn:json-doc("/db/apps/stanford-nlp/data/StanfordCoreNLP-english.json")
112108
};
113109

114110
(:~

0 commit comments

Comments
 (0)