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
|
||||
}
|
||||
|
||||
;(async function entered(e) {
|
||||
async function entered(e) {
|
||||
const searchclient = new MeiliSearch({
|
||||
host: 'https://ms-9ea4a96f02a8-1969.sfo.meilisearch.io',
|
||||
apiKey: '117c691a34b21a6651798479ebffd181eb276958'
|
||||
|
|
@ -205,13 +205,12 @@
|
|||
// const searchResult = await index.search('orgs', {
|
||||
// attributesToRetrieve: ['id']
|
||||
// })
|
||||
const searchResult = await index.search(e.target.value.toString(), {
|
||||
attributesToRetrieve: ['id']
|
||||
})
|
||||
|
||||
const searchResult = await index.search(e.target.value.toString())
|
||||
console.log(searchResult.hits)
|
||||
// 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(
|
||||
resultsgraph => {
|
||||
|
||||
const allNodes = resultsgraph.entities.map((entity: any) => ({
|
||||
data: { id: entity.id, label: entity.label }
|
||||
}))
|
||||
|
|
@ -271,7 +270,7 @@
|
|||
'dGVybWludXNkYjovLy9kYXRhL2tleXNfYXBpLzJkMDU4N2IwYjgzMzhmODdjMjc0ZDdiNmM1MzgwNjFmYTYyMmZkOTcyZTc3NjI1NzIyYjY3MTllYTE3NmQxYjE=_bd6f9c37d87abcaf0c16b7a68335b31010c8dd04aac0b07bf0f31676af131888666200aac080e72cdc746197334eac4f52d821c90652b5611784878afabe1267535cbd896a00a396'
|
||||
}
|
||||
)
|
||||
await client.connect()
|
||||
await client.connect()
|
||||
|
||||
// let v = WOQL.vars('person_id', 'impactarea', '@schema:checked');
|
||||
// const WOQL = TerminusClient.WOQL
|
||||
|
|
@ -294,7 +293,7 @@
|
|||
// console.log('result ', result)
|
||||
// const results = await client.query(query)
|
||||
// console.log('Query Documents using WOQL: ', results.bindings)
|
||||
})()
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="pt-8 p-6 md:p-8 mx-auto">
|
||||
|
|
|
|||
|
|
@ -5,150 +5,121 @@ import * as fs from 'fs'
|
|||
|
||||
const WOQL = TerminusClient.WOQL
|
||||
|
||||
export async function generateKnowledgeGraph(ids: unknown[]): 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[] = []
|
||||
export async function generateKnowledgeGraph(ids: object[]): Promise<object> {
|
||||
const entities: { id: string; label: string; type: string }[] = []
|
||||
const relations: { source: string; target: string; type: string }[] = []
|
||||
for (const id of ids) {
|
||||
const orgid = 'Organization/' + id['id'].toString()
|
||||
const result = await client.getDocument({ as_list: true, type: 'Organization', id: orgid })
|
||||
for (const document of result) {
|
||||
for (const document of ids) {
|
||||
const orgid = 'Organization/' + document['id']
|
||||
let orgEntity = entities.find(entity => entity.id === orgid)
|
||||
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]
|
||||
}
|
||||
|
||||
if (document['assignee'] !== undefined) {
|
||||
const assigneeId = document['assignee']
|
||||
const assigneeId = document['assignee'].replace(/^"|"$/g, '')
|
||||
if (assigneeId !== undefined && assigneeId !== '') {
|
||||
let assigneeEntity = entities.find(entity => entity.id === assigneeId)
|
||||
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]
|
||||
}
|
||||
let assigneeRelation = relations.find(relation => relation.source === orgid && relation.target === assigneeId)
|
||||
let assigneeRelation = relations.find(
|
||||
relation =>
|
||||
relation.source === orgid && relation.target === assigneeId
|
||||
)
|
||||
if (!assigneeRelation) {
|
||||
relations.push({ 'source': orgid, 'target': assigneeId, 'type': 'assignee' })
|
||||
relations.push({
|
||||
source: orgid,
|
||||
target: assigneeId,
|
||||
type: 'assignee'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(document['blockchainecosystem'])) {
|
||||
for (const ecosystem of document['blockchainecosystem']) {
|
||||
const ecosystemId = ecosystem
|
||||
const ecosystems = ['blockchainecosystem', 'web3', 'topic', 'impactarea']
|
||||
for (const ecosystem of ecosystems) {
|
||||
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 !== '') {
|
||||
let ecosystemEntity = entities.find(entity => entity.id === ecosystemId)
|
||||
ecosystemId = ecosystemId.replace(/^"|"$/g, '')
|
||||
let ecosystemEntity = entities.find(
|
||||
entity => entity.id === ecosystemId
|
||||
)
|
||||
if (!ecosystemEntity) {
|
||||
entities.push({ 'id': ecosystemId, 'label': ecosystem, 'type': 'attribute' })
|
||||
entities.push({
|
||||
id: ecosystemId,
|
||||
label: document[ecosystem],
|
||||
type: 'attribute'
|
||||
})
|
||||
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) {
|
||||
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 {
|
||||
'entities': entities,
|
||||
'relations': relations
|
||||
entities: entities,
|
||||
relations: relations
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default generateKnowledgeGraph
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue