Skip to content

Commit

Permalink
Merge pull request #62 from scaife-viewer/develop
Browse files Browse the repository at this point in the history
Actually release performance queries from #57
  • Loading branch information
jacobwegner authored Jul 31, 2020
2 parents 33caaf2 + 3f50dcc commit 56f59a2
Showing 1 changed file with 48 additions and 31 deletions.
79 changes: 48 additions & 31 deletions src/reader/components/NamedEntitiesModeReader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,31 @@
onShowMap(kind) {
this.mapState = kind;
},
getTokenLookup(entities) {
const tokenLookup = {};
entities.forEach(entity => {
const tokenVeRefs = entity.tokens.edges.map(t => t.node.veRef);
tokenVeRefs.forEach(veRef => {
tokenLookup[veRef] = tokenLookup[veRef] || [];
tokenLookup[veRef].push(entity.id);
});
});
return tokenLookup;
},
queryUpdate(data) {
const { edges: parts } = data.passageTextParts;
const entities = data.entities.edges.map(e => e.node);
const parts = data.textParts.edges;
const tokenLookup = this.getTokenLookup(entities);
const lines = parts.map(line => {
const { id, ref } = line.node;
const tokens = line.node.tokens.edges.map(edge => {
const { value, veRef, lemma, namedEntities } = edge.node;
const entities = namedEntities.edges.map(e => e.node.id);
const { value, veRef, lemma } = edge.node;
return {
value,
veRef,
lemma,
entities,
entities: tokenLookup[veRef],
};
});
return {
Expand All @@ -83,25 +96,20 @@
tokens,
};
});
const coordinatesList = parts.map(line => {
return line.node.tokens.edges.map(token => {
return token.node.namedEntities.edges
.map(namedEntity => namedEntity.node)
.filter(node => node.kind === 'PLACE' && node.data.coordinates)
.map(node => {
return [
...node.data.coordinates
.split(', ')
.map(coordinate => parseFloat(coordinate)),
node.id,
node.title,
];
});
const coordinatesList = entities
.filter(entity => entity.kind === 'PLACE' && entity.data.coordinates)
.map(entity => {
return [
...entity.data.coordinates
.split(', ')
.map(coordinate => parseFloat(coordinate)),
entity.id,
entity.title,
];
});
});
return {
lines,
coordinatesList: coordinatesList.flat().flat(),
coordinatesList,
};
},
},
Expand All @@ -126,27 +134,36 @@
query() {
return gql`
query NamedEntities($urn: String!) {
passageTextParts(reference: $urn) {
textParts: passageTextParts(reference: $urn) {
edges {
node {
id
ref
tokens {
edges {
node {
id
veRef
value
lemma
namedEntities {
edges {
node {
id
title
kind
data
}
}
}
}
}
}
}
}
}
entities: namedEntities(reference: $urn) {
edges {
node {
id
title
kind
data
tokens {
edges {
node {
id
veRef
}
}
}
Expand Down

0 comments on commit 56f59a2

Please sign in to comment.