diff --git a/Terminus/test.py b/Terminus/test.py index c57ee59..6dca3b8 100644 --- a/Terminus/test.py +++ b/Terminus/test.py @@ -1,40 +1,2 @@ -import csv -from itertools import islice -from schema import ImpactArea, Blockchain, Topic, Web3, Organization -from terminusdb_client import WOQLClient -from datetime import datetime -import pytz -import re -import emoji - -# we keep all the information in dictionaries with Employee id as keys -orgs = {} - -client = WOQLClient("https://cloud.terminusdb.com/Myseelia/") -client.connect(db="playground3", team="Myseelia", use_token=True) - -import re - - -orgs[0] = Organization( - # assignee = "", - # blockchainecosystem = set(), - # description = "", - # logo = "", - name = "darren" - # preJan20thUpvotes = 0, - # reviewed = "", - # submittedbyemail = "", - # submittedbyname = "", - # submittedbyowner = "", - # subscribed = "", - # topic = set(), - # upvotes = 0, - # web3 = set(), - # impactarea = set(), - # datecreated = datetime.min -) - -client.insert_document(list(orgs.values()), commit_msg="Adding 4 orgs") - - +[{'@id': 'Organization/85405b13178f8e090cbcd58fd22111c0f72f77b59cbe00bb389ecd04c41d0e90', '@type': 'Organization', 'assignee': 'https://2local.io/', 'blockchainecosystem': ['BinanceSmartChain'], 'datecreated': '2022-05-07T11:03:00Z', 'description': '2local loyalty platform with the goal to achieve a sustainable world with prosperity for all. The cashback system supports sustainable and local-to-local working businesses. This cashback is generated from the profit from Yield Farms and Staking Pools. 2local doesn’t profit from its users but creates value with its users.', 'impactarea': ['SocialJustice'], 'name': '2local.io', + 'preJan20thUpvotes': '4', 'reviewed': 'checked', 'topic': ['Marketplace'], 'upvotes': '4'}, {'@id': 'Organization/f2dd1e11327e68d3ca3550cdec338186032d4fc4de4e9924ff97a8260a549be7', '@type': 'Organization', 'assignee': 'https://www.acredaos.com/', 'blockchainecosystem': ['Ethereum'], 'datecreated': '2022-05-07T11:03:00Z', 'description': 'ACRE DAOs is a decentralized impact investment club and Web3 access portal to the community of ACRE Invest token holders.', 'impactarea': ['SocialJustice'], 'name': 'ACRE DAOs\n', 'preJan20thUpvotes': '2', 'reviewed': 'checked', 'topic': ['Investing', 'Land'], 'upvotes': '2', 'web3': ['DAO']}] diff --git a/src/components/CTA/CTA copy.svelte b/src/components/CTA/CTA copy.svelte new file mode 100644 index 0000000..57767f4 --- /dev/null +++ b/src/components/CTA/CTA copy.svelte @@ -0,0 +1,290 @@ + + +
+ { + if (event.keyCode === 13) { + entered(event) + } + }} + /> +
+
+
+ +
+
+ + diff --git a/src/components/CTA/CTA.svelte b/src/components/CTA/CTA.svelte index 57767f4..5d32906 100644 --- a/src/components/CTA/CTA.svelte +++ b/src/components/CTA/CTA.svelte @@ -41,20 +41,6 @@ let edges: IEdge[] = [] onMount(async () => { - nodes = knowledgeGraphJson.entities.map((entity: any) => ({ - data: { id: entity.id, label: entity.label } - })) - - edges = knowledgeGraphJson.relations.map( - (relation: any, index: string) => ({ - data: { - id: index, - source: relation.source, - target: relation.target, - label: relation.type - } - }) - ) cy = cytoscape({ container: document.getElementById('cy'), @@ -113,6 +99,51 @@ } }) + const searchclient = new MeiliSearch({ + host: 'https://ms-9ea4a96f02a8-1969.sfo.meilisearch.io', + apiKey: '117c691a34b21a6651798479ebffd181eb276958' + }) + const index = searchclient.index('people') + // this will search both keys and values + // const search = await index.search(e.target.value.toString(), { q: '*' }); + // const searchResult = await index.search('orgs', { + // attributesToRetrieve: ['id'] + // }) + const searchResult = await index.getDocuments( + { + limit: 1000 + } + ) + console.log(searchResult) + // 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.results).then( + resultsgraph => { + + console.log(resultsgraph) + const allNodes = resultsgraph.entities.map((entity: any) => ({ + data: { id: entity.id, label: entity.label } + })) + + const allEdges = resultsgraph.relations.map( + (relation: any, index: string) => ({ + data: { + id: index, + source: relation.source, + target: relation.target, + label: relation.type + } + }) + ) + cy.remove(cy.elements()) + cy.add(allNodes) + cy.add(allEdges) + cy.layout({ + name: 'cose' + // other layout options here + }).run() + } + ) + cy.nodes().forEach(function (node) { node.data({ degree: node.connectedEdges().length diff --git a/src/components/CTA/cytoscape.ts b/src/components/CTA/cytoscape.ts index 66af2f9..37f69ba 100644 --- a/src/components/CTA/cytoscape.ts +++ b/src/components/CTA/cytoscape.ts @@ -5,17 +5,24 @@ import * as fs from 'fs' const WOQL = TerminusClient.WOQL +function findNameById(ids: object[], id: string): string { + console.log('finding id ' + id); + const document = ids.find(doc => 'person/' + doc['id'] === id); + console.log('found name ' + JSON.parse(document['name'])); + return document ? JSON.parse(document['name']) : ''; +} + export async function generateKnowledgeGraph(ids: object[]): Promise { - console.log(ids) const entities: { id: string; label: string; type: string }[] = [] const relations: { source: string; target: string; type: string }[] = [] + for (const document of ids) { - const personid = 'Person/' + document['id'] + const personid = 'person/' + document['id'] let personEntity = entities.find(entity => entity.id === personid) if (!personEntity) { entities.push({ id: personid, - label: document['name'], + label: typeof document['name'] === 'string' && document['name'].startsWith('"') && document['name'].endsWith('"') ? JSON.parse(document['name']) : document['name'], type: 'person' }) personEntity = entities[entities.length - 1] @@ -23,25 +30,27 @@ export async function generateKnowledgeGraph(ids: object[]): Promise { const linktypes = ['vouches_for', 'LI'] for (const link of linktypes) { - let linkValues = document[link] - try { - linkValues = JSON.parse(linkValues) - } catch (error) { - console.log(error) + let linkValues = document[link]; + if (typeof linkValues === 'string') { + try { + linkValues = JSON.parse(linkValues); + } catch (error) { + console.error(`Error parsing JSON for link "${link}":`, error); + } } if (Array.isArray(linkValues)) { for (const linkValue of linkValues) { if (linkValue === undefined) continue const linkId = linkValue.replace(/^"|"$/g, '') - if (linkId !== undefined && linkId !== '') { + if (linkId !== undefined && linkId !== '' && linkId.startsWith('person/')) { let linkEntity = entities.find( entity => entity.id === linkId ) if (!linkEntity) { entities.push({ id: linkId, - label: linkValue, - type: 'attribute' + label: findNameById(ids, linkId), + type: 'person' }) linkEntity = entities[entities.length - 1] } @@ -60,8 +69,7 @@ export async function generateKnowledgeGraph(ids: object[]): Promise { } } else { let linkId = linkValues - // console.log(linkId) - if (linkId !== undefined && linkId !== '') { + if (linkId !== undefined && linkId !== '' && linkId.startsWith('person/')) { linkId = linkId.replace(/^"|"$/g, '') let linkEntity = entities.find( entity => entity.id === linkId @@ -70,7 +78,7 @@ export async function generateKnowledgeGraph(ids: object[]): Promise { entities.push({ id: linkId, label: document[link], - type: 'attribute' + type: 'person' }) linkEntity = entities[entities.length - 1] } diff --git a/src/components/explore/Explore.svelte b/src/components/explore/Explore.svelte index 56be375..45cbe2a 100644 --- a/src/components/explore/Explore.svelte +++ b/src/components/explore/Explore.svelte @@ -256,6 +256,7 @@ top: 10px; z-index: 100; background-color: white; + color: black; width: 50%; height: 40px; border-radius: 20px; diff --git a/src/routes/cta/components/imageGallery/ImageGallery.svelte b/src/routes/cta/components/imageGallery/ImageGallery.svelte index ca88760..d6cbc25 100644 --- a/src/routes/cta/components/imageGallery/ImageGallery.svelte +++ b/src/routes/cta/components/imageGallery/ImageGallery.svelte @@ -5,10 +5,11 @@ import TerminusClient from "@terminusdb/terminusdb-client" import { filesystemStore, sessionStore } from '$src/stores' import { AREAS, galleryStore } from '$routes/gallery/stores' - import { getImagesFromWNFS, type Image } from '$routes/gallery/lib/gallery' + import { getJSONFromWNFS, type Image } from '$routes/gallery/lib/gallery' import FileUploadCard from '$routes/gallery/components/upload/FileUploadCard.svelte' import ImageCard from '$routes/gallery/components/imageGallery/ImageCard.svelte' import ImageModal from '$routes/gallery/components/imageGallery/ImageModal.svelte' + import { ipfsGatewayUrl } from '$lib/app-info'; const client = new TerminusClient.WOQLClient( "https://cloud.terminusdb.com/Myseelia",{ @@ -42,7 +43,7 @@ const clearSelectedImage = () => (selectedImage = null) - // If galleryStore.selectedArea changes from private to public, re-run getImagesFromWNFS + // If galleryStore.selectedArea changes from private to public, re-run getJSONFromWNFS let selectedArea = null const unsubscribeGalleryStore = galleryStore.subscribe(async updatedStore => { // Get initial selectedArea @@ -52,7 +53,7 @@ if (selectedArea !== updatedStore.selectedArea) { selectedArea = updatedStore.selectedArea - await getImagesFromWNFS() + await getJSONFromWNFS() } }) @@ -62,7 +63,7 @@ if (newState.authed && $filesystemStore && !imagesFetched) { imagesFetched = true // Get images from the user's public WNFS - getImagesFromWNFS() + getJSONFromWNFS() } }) @@ -162,6 +163,13 @@ button{
+ {#if selectedImage} diff --git a/src/routes/cta/components/imageGallery/MyseeliaPublic.svelte b/src/routes/cta/components/imageGallery/MyseeliaPublic.svelte index 55a3366..875f84d 100644 --- a/src/routes/cta/components/imageGallery/MyseeliaPublic.svelte +++ b/src/routes/cta/components/imageGallery/MyseeliaPublic.svelte @@ -4,7 +4,7 @@ import { filesystemStore, sessionStore } from '$src/stores' import { AREAS, galleryStore } from '$routes/gallery/stores' - import { getImagesFromWNFS, type Image } from '$routes/gallery/lib/gallery' + import { getJSONFromWNFS, type Image } from '$routes/gallery/lib/gallery' import FileUploadCard from '$routes/gallery/components/upload/FileUploadCard.svelte' import ImageCard from '$routes/gallery/components/imageGallery/ImageCard.svelte' import ImageModal from '$routes/gallery/components/imageGallery/ImageModal.svelte' @@ -17,7 +17,7 @@ const setSelectedImage: (image: Image) => void = image => (selectedImage = image) - // If galleryStore.selectedArea changes from private to public, re-run getImagesFromWNFS + // If galleryStore.selectedArea changes from private to public, re-run getJSONFromWNFS let selectedArea = null const unsubscribeGalleryStore = galleryStore.subscribe(async updatedStore => { // Get initial selectedArea @@ -36,7 +36,7 @@ if (newState.authed && $filesystemStore && !imagesFetched) { imagesFetched = true // Get images from the user's public WNFS - getImagesFromWNFS() + getJSONFromWNFS() } }) diff --git a/src/routes/cta/components/upload/Dropzone.svelte b/src/routes/cta/components/upload/Dropzone.svelte index b4b4e3c..229aea7 100644 --- a/src/routes/cta/components/upload/Dropzone.svelte +++ b/src/routes/cta/components/upload/Dropzone.svelte @@ -1,7 +1,7 @@ - -

+
+
+ + +
-
-
- + +
+ +
+ {#if cid !== null && cid !== undefined} + +
+ + {/if}
@@ -172,3 +364,37 @@ button{ /> {/if}
+ + diff --git a/src/routes/gallery/components/imageGallery/MyseeliaPublic.svelte b/src/routes/gallery/components/imageGallery/MyseeliaPublic.svelte index 55a3366..fc67cf9 100644 --- a/src/routes/gallery/components/imageGallery/MyseeliaPublic.svelte +++ b/src/routes/gallery/components/imageGallery/MyseeliaPublic.svelte @@ -4,7 +4,7 @@ import { filesystemStore, sessionStore } from '$src/stores' import { AREAS, galleryStore } from '$routes/gallery/stores' - import { getImagesFromWNFS, type Image } from '$routes/gallery/lib/gallery' + import { getJSONFromWNFS, type Image } from '$routes/gallery/lib/gallery' import FileUploadCard from '$routes/gallery/components/upload/FileUploadCard.svelte' import ImageCard from '$routes/gallery/components/imageGallery/ImageCard.svelte' import ImageModal from '$routes/gallery/components/imageGallery/ImageModal.svelte' @@ -17,7 +17,7 @@ const setSelectedImage: (image: Image) => void = image => (selectedImage = image) - // If galleryStore.selectedArea changes from private to public, re-run getImagesFromWNFS + // If galleryStore.selectedArea changes from private to public, re-run getImaggetJSONFromWNFSesFromWNFS let selectedArea = null const unsubscribeGalleryStore = galleryStore.subscribe(async updatedStore => { // Get initial selectedArea @@ -36,7 +36,7 @@ if (newState.authed && $filesystemStore && !imagesFetched) { imagesFetched = true // Get images from the user's public WNFS - getImagesFromWNFS() + getJSONFromWNFS() } }) diff --git a/src/routes/gallery/components/upload/Dropzone.svelte b/src/routes/gallery/components/upload/Dropzone.svelte index b4b4e3c..229aea7 100644 --- a/src/routes/gallery/components/upload/Dropzone.svelte +++ b/src/routes/gallery/components/upload/Dropzone.svelte @@ -1,7 +1,7 @@