change search to only query the index not TerminusDB
This commit is contained in:
parent
01631078ab
commit
df4707ff7b
|
|
@ -194,7 +194,7 @@
|
||||||
// Perform search in real timebased on searchTerm here
|
// Perform search in real timebased on searchTerm here
|
||||||
}
|
}
|
||||||
|
|
||||||
;(async function entered(e) {
|
async function entered(e) {
|
||||||
const searchclient = new MeiliSearch({
|
const searchclient = new MeiliSearch({
|
||||||
host: 'https://ms-9ea4a96f02a8-1969.sfo.meilisearch.io',
|
host: 'https://ms-9ea4a96f02a8-1969.sfo.meilisearch.io',
|
||||||
apiKey: '117c691a34b21a6651798479ebffd181eb276958'
|
apiKey: '117c691a34b21a6651798479ebffd181eb276958'
|
||||||
|
|
@ -205,13 +205,12 @@
|
||||||
// const searchResult = await index.search('orgs', {
|
// const searchResult = await index.search('orgs', {
|
||||||
// attributesToRetrieve: ['id']
|
// attributesToRetrieve: ['id']
|
||||||
// })
|
// })
|
||||||
const searchResult = await index.search(e.target.value.toString(), {
|
const searchResult = await index.search(e.target.value.toString())
|
||||||
attributesToRetrieve: ['id']
|
console.log(searchResult.hits)
|
||||||
})
|
|
||||||
|
|
||||||
// need to turn the search results into an array of ids which can be used to query the knowledge graph
|
// need to turn the search results into an array of ids which can be used to query the knowledge graph
|
||||||
const resultsgraph = await generateKnowledgeGraph(searchResult.hits).then(
|
const resultsgraph = await generateKnowledgeGraph(searchResult.hits).then(
|
||||||
resultsgraph => {
|
resultsgraph => {
|
||||||
|
|
||||||
const allNodes = resultsgraph.entities.map((entity: any) => ({
|
const allNodes = resultsgraph.entities.map((entity: any) => ({
|
||||||
data: { id: entity.id, label: entity.label }
|
data: { id: entity.id, label: entity.label }
|
||||||
}))
|
}))
|
||||||
|
|
@ -271,7 +270,7 @@
|
||||||
'dGVybWludXNkYjovLy9kYXRhL2tleXNfYXBpLzJkMDU4N2IwYjgzMzhmODdjMjc0ZDdiNmM1MzgwNjFmYTYyMmZkOTcyZTc3NjI1NzIyYjY3MTllYTE3NmQxYjE=_bd6f9c37d87abcaf0c16b7a68335b31010c8dd04aac0b07bf0f31676af131888666200aac080e72cdc746197334eac4f52d821c90652b5611784878afabe1267535cbd896a00a396'
|
'dGVybWludXNkYjovLy9kYXRhL2tleXNfYXBpLzJkMDU4N2IwYjgzMzhmODdjMjc0ZDdiNmM1MzgwNjFmYTYyMmZkOTcyZTc3NjI1NzIyYjY3MTllYTE3NmQxYjE=_bd6f9c37d87abcaf0c16b7a68335b31010c8dd04aac0b07bf0f31676af131888666200aac080e72cdc746197334eac4f52d821c90652b5611784878afabe1267535cbd896a00a396'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
await client.connect()
|
await client.connect()
|
||||||
|
|
||||||
// let v = WOQL.vars('person_id', 'impactarea', '@schema:checked');
|
// let v = WOQL.vars('person_id', 'impactarea', '@schema:checked');
|
||||||
// const WOQL = TerminusClient.WOQL
|
// const WOQL = TerminusClient.WOQL
|
||||||
|
|
@ -294,7 +293,7 @@
|
||||||
// console.log('result ', result)
|
// console.log('result ', result)
|
||||||
// const results = await client.query(query)
|
// const results = await client.query(query)
|
||||||
// console.log('Query Documents using WOQL: ', results.bindings)
|
// console.log('Query Documents using WOQL: ', results.bindings)
|
||||||
})()
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="pt-8 p-6 md:p-8 mx-auto">
|
<div class="pt-8 p-6 md:p-8 mx-auto">
|
||||||
|
|
|
||||||
|
|
@ -5,150 +5,121 @@ import * as fs from 'fs'
|
||||||
|
|
||||||
const WOQL = TerminusClient.WOQL
|
const WOQL = TerminusClient.WOQL
|
||||||
|
|
||||||
export async function generateKnowledgeGraph(ids: unknown[]): Promise<object> {
|
export async function generateKnowledgeGraph(ids: object[]): Promise<object> {
|
||||||
const client = new TerminusClient.WOQLClient(
|
|
||||||
'https://cloud.terminusdb.com/Myseelia/',
|
|
||||||
{
|
|
||||||
user: 'zaldarren@gmail.com',
|
|
||||||
organization: 'Myseelia',
|
|
||||||
db: 'play',
|
|
||||||
token:
|
|
||||||
'dGVybWludXNkYjovLy9kYXRhL2tleXNfYXBpLzJkMDU4N2IwYjgzMzhmODdjMjc0ZDdiNmM1MzgwNjFmYTYyMmZkOTcyZTc3NjI1NzIyYjY3MTllYTE3NmQxYjE=_bd6f9c37d87abcaf0c16b7a68335b31010c8dd04aac0b07bf0f31676af131888666200aac080e72cdc746197334eac4f52d821c90652b5611784878afabe1267535cbd896a00a396'
|
|
||||||
}
|
|
||||||
)
|
|
||||||
await client.connect()
|
|
||||||
const results: unknown[] = []
|
|
||||||
const entities: { id: string; label: string; type: string }[] = []
|
const entities: { id: string; label: string; type: string }[] = []
|
||||||
const relations: { source: string; target: string; type: string }[] = []
|
const relations: { source: string; target: string; type: string }[] = []
|
||||||
for (const id of ids) {
|
for (const document of ids) {
|
||||||
const orgid = 'Organization/' + id['id'].toString()
|
const orgid = 'Organization/' + document['id']
|
||||||
const result = await client.getDocument({ as_list: true, type: 'Organization', id: orgid })
|
|
||||||
for (const document of result) {
|
|
||||||
let orgEntity = entities.find(entity => entity.id === orgid)
|
let orgEntity = entities.find(entity => entity.id === orgid)
|
||||||
if (!orgEntity) {
|
if (!orgEntity) {
|
||||||
entities.push({ 'id': orgid, 'label': document['name'], 'type': 'organization' })
|
entities.push({
|
||||||
|
id: orgid,
|
||||||
|
label: document['name'],
|
||||||
|
type: 'organization'
|
||||||
|
})
|
||||||
orgEntity = entities[entities.length - 1]
|
orgEntity = entities[entities.length - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document['assignee'] !== undefined) {
|
if (document['assignee'] !== undefined) {
|
||||||
const assigneeId = document['assignee']
|
const assigneeId = document['assignee'].replace(/^"|"$/g, '')
|
||||||
if (assigneeId !== undefined && assigneeId !== '') {
|
if (assigneeId !== undefined && assigneeId !== '') {
|
||||||
let assigneeEntity = entities.find(entity => entity.id === assigneeId)
|
let assigneeEntity = entities.find(entity => entity.id === assigneeId)
|
||||||
if (!assigneeEntity) {
|
if (!assigneeEntity) {
|
||||||
entities.push({ 'id': assigneeId, 'label': document['name'] + ' assignee', 'type': 'attribute' })
|
entities.push({
|
||||||
|
id: assigneeId,
|
||||||
|
label: document['name'] + ' assignee',
|
||||||
|
type: 'attribute'
|
||||||
|
})
|
||||||
assigneeEntity = entities[entities.length - 1]
|
assigneeEntity = entities[entities.length - 1]
|
||||||
}
|
}
|
||||||
let assigneeRelation = relations.find(relation => relation.source === orgid && relation.target === assigneeId)
|
let assigneeRelation = relations.find(
|
||||||
|
relation =>
|
||||||
|
relation.source === orgid && relation.target === assigneeId
|
||||||
|
)
|
||||||
if (!assigneeRelation) {
|
if (!assigneeRelation) {
|
||||||
relations.push({ 'source': orgid, 'target': assigneeId, 'type': 'assignee' })
|
relations.push({
|
||||||
|
source: orgid,
|
||||||
|
target: assigneeId,
|
||||||
|
type: 'assignee'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(document['blockchainecosystem'])) {
|
const ecosystems = ['blockchainecosystem', 'web3', 'topic', 'impactarea']
|
||||||
for (const ecosystem of document['blockchainecosystem']) {
|
for (const ecosystem of ecosystems) {
|
||||||
const ecosystemId = ecosystem
|
let ecosystemValues = document[ecosystem]
|
||||||
|
try {
|
||||||
|
ecosystemValues = JSON.parse(ecosystemValues)
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
if (Array.isArray(ecosystemValues)) {
|
||||||
|
console.log(ecosystemValues)
|
||||||
|
for (const ecosystemValue of ecosystemValues) {
|
||||||
|
if(ecosystemValue === undefined) continue;
|
||||||
|
const ecosystemId = ecosystemValue.replace(/^"|"$/g, '')
|
||||||
|
if (ecosystemId !== undefined && ecosystemId !== '') {
|
||||||
|
let ecosystemEntity = entities.find(
|
||||||
|
entity => entity.id === ecosystemId
|
||||||
|
)
|
||||||
|
if (!ecosystemEntity) {
|
||||||
|
entities.push({
|
||||||
|
id: ecosystemId,
|
||||||
|
label: ecosystemValue,
|
||||||
|
type: 'attribute'
|
||||||
|
})
|
||||||
|
ecosystemEntity = entities[entities.length - 1]
|
||||||
|
}
|
||||||
|
let ecosystemRelation = relations.find(
|
||||||
|
relation =>
|
||||||
|
relation.source === orgid && relation.target === ecosystemId
|
||||||
|
)
|
||||||
|
if (!ecosystemRelation) {
|
||||||
|
relations.push({
|
||||||
|
source: orgid,
|
||||||
|
target: ecosystemId,
|
||||||
|
type: ecosystem
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let ecosystemId = ecosystemValues
|
||||||
|
// console.log(ecosystemId)
|
||||||
if (ecosystemId !== undefined && ecosystemId !== '') {
|
if (ecosystemId !== undefined && ecosystemId !== '') {
|
||||||
let ecosystemEntity = entities.find(entity => entity.id === ecosystemId)
|
ecosystemId = ecosystemId.replace(/^"|"$/g, '')
|
||||||
|
let ecosystemEntity = entities.find(
|
||||||
|
entity => entity.id === ecosystemId
|
||||||
|
)
|
||||||
if (!ecosystemEntity) {
|
if (!ecosystemEntity) {
|
||||||
entities.push({ 'id': ecosystemId, 'label': ecosystem, 'type': 'attribute' })
|
entities.push({
|
||||||
|
id: ecosystemId,
|
||||||
|
label: document[ecosystem],
|
||||||
|
type: 'attribute'
|
||||||
|
})
|
||||||
ecosystemEntity = entities[entities.length - 1]
|
ecosystemEntity = entities[entities.length - 1]
|
||||||
}
|
}
|
||||||
let ecosystemRelation = relations.find(relation => relation.source === orgid && relation.target === ecosystemId)
|
let ecosystemRelation = relations.find(
|
||||||
|
relation =>
|
||||||
|
relation.source === orgid && relation.target === ecosystemId
|
||||||
|
)
|
||||||
if (!ecosystemRelation) {
|
if (!ecosystemRelation) {
|
||||||
relations.push({ 'source': orgid, 'target': ecosystemId, 'type': 'blockchain ecosystem' })
|
relations.push({
|
||||||
|
source: orgid,
|
||||||
|
target: ecosystemId,
|
||||||
|
type: ecosystem
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const ecosystemId = document['blockchainecosystem']
|
|
||||||
if (ecosystemId !== undefined && ecosystemId !== '') {
|
|
||||||
let ecosystemEntity = entities.find(entity => entity.id === ecosystemId)
|
|
||||||
if (!ecosystemEntity) {
|
|
||||||
entities.push({ 'id': ecosystemId, 'label': document['blockchainecosystem'], 'type': 'attribute' })
|
|
||||||
ecosystemEntity = entities[entities.length - 1]
|
|
||||||
}
|
|
||||||
let ecosystemRelation = relations.find(relation => relation.source === orgid && relation.target === ecosystemId)
|
|
||||||
if (!ecosystemRelation) {
|
|
||||||
relations.push({ 'source': orgid, 'target': ecosystemId, 'type': 'blockchain ecosystem' })
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(document['topic'])) {
|
|
||||||
for (const topic of document['topic']) {
|
|
||||||
const topicId = topic
|
|
||||||
if (topicId !== undefined && topicId !== '') {
|
|
||||||
let topicEntity = entities.find(entity => entity.id === topicId)
|
|
||||||
if (!topicEntity) {
|
|
||||||
entities.push({ 'id': topicId, 'label': topic, 'type': 'attribute' })
|
|
||||||
topicEntity = entities[entities.length - 1]
|
|
||||||
}
|
|
||||||
let topicRelation = relations.find(relation => relation.source === orgid && relation.target === topicId)
|
|
||||||
if (!topicRelation) {
|
|
||||||
relations.push({ 'source': orgid, 'target': topicId, 'type': 'topic' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const topicId = document['topic']
|
|
||||||
if (topicId !== undefined && topicId !== '') {
|
|
||||||
let topicEntity = entities.find(entity => entity.id === topicId)
|
|
||||||
if (!topicEntity) {
|
|
||||||
entities.push({ 'id': topicId, 'label': document['topic'], 'type': 'attribute' })
|
|
||||||
topicEntity = entities[entities.length - 1]
|
|
||||||
}
|
|
||||||
let topicRelation = relations.find(relation => relation.source === orgid && relation.target === topicId)
|
|
||||||
if (!topicRelation) {
|
|
||||||
relations.push({ 'source': orgid, 'target': topicId, 'type': 'topic' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(document['web3'])) {
|
|
||||||
for (const web3 of document['web3']) {
|
|
||||||
const web3Id = web3
|
|
||||||
if (web3Id !== undefined && web3Id !== '') {
|
|
||||||
let web3Entity = entities.find(entity => entity.id === web3Id)
|
|
||||||
if (!web3Entity) {
|
|
||||||
entities.push({ 'id': web3Id, 'label': web3, 'type': 'attribute' })
|
|
||||||
web3Entity = entities[entities.length - 1]
|
|
||||||
}
|
|
||||||
let web3Relation = relations.find(relation => relation.source === orgid && relation.target === web3Id)
|
|
||||||
if (!web3Relation) {
|
|
||||||
relations.push({ 'source': orgid, 'target': web3Id, 'type': 'web3' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const web3Id = document['web3']
|
|
||||||
if (web3Id !== undefined && web3Id !== '') {
|
|
||||||
let web3Entity = entities.find(entity => entity.id === web3Id)
|
|
||||||
if (!web3Entity) {
|
|
||||||
entities.push({ 'id': web3Id, 'label': document['web3'], 'type': 'attribute' })
|
|
||||||
web3Entity = entities[entities.length - 1]
|
|
||||||
}
|
|
||||||
let web3Relation = relations.find(relation => relation.source === orgid && relation.target === web3Id)
|
|
||||||
if (!web3Relation) {
|
|
||||||
relations.push({ 'source': orgid, 'target': web3Id, 'type': 'web3' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log(entities)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'entities': entities,
|
entities: entities,
|
||||||
'relations': relations
|
relations: relations
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default generateKnowledgeGraph
|
export default generateKnowledgeGraph
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue