Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Bug fixes for document viewer for documents with WikiData items (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringgaard authored Nov 14, 2018
1 parent 938c01d commit b8b1234
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
25 changes: 14 additions & 11 deletions app/lib/docview.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ stylesheet("/common/style/docview.css");
let kb_url = '/kb/?id=';

let type_color = {
'/s': '#0B5394',
'/s': '#FF8000',
'/saft': '#38761D',
'/pb': '#990000',
'/vn': '#8B4513',
'/f': '#FF8000',
'/cxn': '#630084',
'/w': '#0B5394',
};

let notchgif = 'data:image/gif;base64,R0lGODlhDAAWAJEAAP/68NK8jv///' +
Expand Down Expand Up @@ -54,7 +53,7 @@ export class Document {
if (a.begin != b.begin) {
return a.begin - b.begin;
} else {
return a.end - b.end;
return b.end - a.end;
}
});
}
Expand Down Expand Up @@ -262,7 +261,7 @@ export class DocumentViewer extends Component {
text += "id: " + frame.id + '\n';
}
if (frame.description) {
text += "description: " + frame.description + '\n';
text += frame.description + '\n';
}
return text;
}
Expand All @@ -282,11 +281,13 @@ export class DocumentViewer extends Component {

IsExternal(f) {
if (typeof f == "number") f = this.document.frames[f];
for (let t = 0; t < f.types.length; ++t) {
let type = f.types[t];
if (typeof type == "number") {
let schema = this.document.frames[type];
if (schema.id == "/w/item") return true;
if (typeof f == "object") {
for (let t = 0; t < f.types.length; ++t) {
let type = f.types[t];
if (typeof type == "number") {
let schema = this.document.frames[type];
if (schema.id == "/w/item") return true;
}
}
}
return false;
Expand Down Expand Up @@ -360,14 +361,15 @@ export class DocumentViewer extends Component {
if (this.IsExternal(frame)) {
let a = document.createElement("a");
a.href = kb_url + frame.id;
a.target = " _blank";
a.appendChild(name);
name = a
} else {
let s = document.createElement("span");
s.appendChild(name);
name = s;
}
name.setAttribute("tooltip", frame.id);
name.setAttribute("tooltip", this.HoverText(frame));
}
title.appendChild(name);
}
Expand Down Expand Up @@ -421,6 +423,7 @@ export class DocumentViewer extends Component {
if (this.IsExternal(v)) {
let a = document.createElement("a");
a.href = kb_url + v;
a.target = "_blank";
a.appendChild(document.createTextNode(v));
val.appendChild(a);
} else {
Expand Down
7 changes: 3 additions & 4 deletions app/style/docview.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ a {
}

a:link {
text-decoration: none;
text-decoration: underline;
}

a:visited {
text-decoration: none;
text-decoration: underline;
}

.doctext {
Expand Down Expand Up @@ -234,7 +234,7 @@ a:visited {
left: -12px;
}

span[tooltip]:hover:before {
a[tooltip]:hover:before, span[tooltip]:hover:before {
content: attr(tooltip);
font: 11pt arial;
position: absolute;
Expand All @@ -246,4 +246,3 @@ span[tooltip]:hover:before {
background: #666;
white-space: pre-wrap;
}

2 changes: 2 additions & 0 deletions sling/nlp/document/document-service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Frame DocumentService::Convert(const Document &document) {
mapping.Add(Handle::isa());
mapping.Add(Handle::is());
mapping.Add(n_name_.handle());
mapping.Add(n_item_.handle());
mapping.Add(n_property_.handle());

// Add all evoked frames.
Handles queue(store);
Expand Down
3 changes: 3 additions & 0 deletions sling/nlp/document/document-service.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class DocumentService {
Name n_begin_{names_, "begin"};
Name n_end_{names_, "end"};
Name n_frame_{names_, "frame"};

Name n_item_{names_, "/w/item"};
Name n_property_{names_, "/w/property"};
};

} // namespace nlp
Expand Down
10 changes: 5 additions & 5 deletions sling/nlp/kb/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ <h2><span>{{active.title}}</span></h2>
{{item.text}}
</span>
<span class="extref">
(<a ng-href="https://www.wikidata.org/wiki/{{item.ref}}">{{item.ref}}</a>)
(<a ng-href="https://www.wikidata.org/wiki/{{item.ref}}" target="_blank">{{item.ref}}</a>)
</span>
<span flex></span>
<md-button class="md-icon-button">
<a ng-href="https://www.wikidata.org/wiki/Special:EntityData/{{item.ref}}.json">
<a ng-href="https://www.wikidata.org/wiki/Special:EntityData/{{item.ref}}.json" target="_blank">
<i class="material-icons">library_books</i>
</a>
</md-button>
<md-button class="md-icon-button">
<a ng-href="/kb/item?fmt=json&id={{item.ref}}">
<a ng-href="/kb/item?fmt=json&id={{item.ref}}" target="_blank">
<i class="material-icons">code</i>
</a>
</md-button>
<md-button class="md-icon-button">
<a ng-href="/kb/frame?fmt=txt&id={{item.ref}}">
<a ng-href="/kb/frame?fmt=txt&id={{item.ref}}" target="_blank">
<i class="material-icons">input</i>
</a>
</md-button>
Expand Down Expand Up @@ -229,7 +229,7 @@ <h2><span>{{active.title}}</span></h2>
</td>
<td class="xref-values">
<div class="xref-value" ng-repeat="v in x.values">
<a ng-href="{{v.url}}">{{v.text}}</a>
<a ng-href="{{v.url}}" target="_blank">{{v.text}}</a>
</div>
</td>
</tr>
Expand Down

0 comments on commit b8b1234

Please sign in to comment.