Skip to content

Commit 536afb2

Browse files
committed
clean
Signed-off-by: Dan Selman <[email protected]>
1 parent 454e856 commit 536afb2

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

src/demo/index.ts

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { GraphModel, GraphModelOptions, getOpenAiEmbedding } from '../graphmodel.js'
22

3+
const NS = '[email protected]';
4+
35
const MODEL = `
4-
6+
namespace ${NS}
57
import [email protected].{GraphNode}
68
79
// show how a complex type gets flattened
@@ -14,10 +16,6 @@ concept Address {
1416
o String country
1517
}
1618
17-
concept PersonProperties extends GraphNode {
18-
o Address address
19-
}
20-
2119
concept Person extends GraphNode {
2220
o Address address optional
2321
@label("ACTED_IN")
@@ -50,7 +48,7 @@ concept Movie extends GraphNode {
5048
}
5149
`;
5250

53-
async function run(): Promise<GraphModel> {
51+
async function run() {
5452
const options:GraphModelOptions = {
5553
NEO4J_USER: process.env.NEO4J_USER,
5654
NEO4J_PASS: process.env.NEO4J_PASS,
@@ -75,21 +73,39 @@ async function run(): Promise<GraphModel> {
7573
state: 'CO',
7674
country: 'USA'
7775
};
78-
const summary = 'The film centres on Sam Lowry, a low-ranking bureaucrat trying to find a woman who appears in his dreams while he is working in a mind-numbing job and living in a small apartment, set in a dystopian world in which there is an over-reliance on poorly maintained (and rather whimsical) machines';
79-
await graphModel.mergeNode(transaction, '[email protected]', {identifier: 'Brazil', summary} );
80-
await graphModel.mergeNode(transaction, '[email protected]', {identifier: 'Terry Gilliam'} );
81-
await graphModel.mergeRelationship(transaction, '[email protected]', 'Terry Gilliam', '[email protected]', 'Brazil', 'directed' );
82-
await graphModel.mergeNode(transaction, '[email protected]', {identifier: 'Dan', address} );
83-
await graphModel.mergeRelationship(transaction, '[email protected]', 'Dan', '[email protected]', 'Brazil', 'ratedMovies' );
84-
await graphModel.mergeNode(transaction, '[email protected]', {identifier: 'Jonathan Pryce'} );
85-
await graphModel.mergeRelationship(transaction, '[email protected]', 'Jonathan Pryce', '[email protected]', 'Brazil', 'actedIn' );
86-
const search = 'working in a mind-numbing job and living in a small apartment';
87-
const results = await graphModel.similarityQuery('[email protected]', 'embedding', search, 3);
76+
await graphModel.mergeNode(transaction, `${NS}.Movie`, {identifier: 'Brazil', summary: 'The film centres on Sam Lowry, a low-ranking bureaucrat trying to find a woman who appears in his dreams while he is working in a mind-numbing job and living in a small apartment, set in a dystopian world in which there is an over-reliance on poorly maintained (and rather whimsical) machines'} );
77+
await graphModel.mergeNode(transaction, `${NS}.Movie`, {identifier: 'The Man Who Killed Don Quixote', summary: 'Instead of a literal adaptation, Gilliam\'s film was about "an old, retired, and slightly kooky nobleman named Alonso Quixano".'} );
78+
await graphModel.mergeNode(transaction, `${NS}.Movie`, {identifier: 'Fear and Loathing in Las Vegas', summary: 'Duke, under the influence of mescaline, complains of a swarm of giant bats, and inventories their drug stash. They pick up a young hitchhiker and explain their mission: Duke has been assigned by a magazine to cover the Mint 400 motorcycle race in Las Vegas. They bought excessive drugs for the trip, and rented a red Chevrolet Impala convertible.'} );
79+
80+
await graphModel.mergeNode(transaction, `${NS}.Genre`, {identifier: 'Comedy'} );
81+
await graphModel.mergeNode(transaction, `${NS}.Genre`, {identifier: 'Science Fiction'} );
82+
83+
await graphModel.mergeRelationship(transaction, `${NS}.Movie`, 'Brazil', `${NS}.Genre`, 'Comedy', 'genres' );
84+
await graphModel.mergeRelationship(transaction, `${NS}.Movie`, 'Brazil', `${NS}.Genre`, 'Science Fiction', 'genres' );
85+
await graphModel.mergeRelationship(transaction, `${NS}.Movie`, 'The Man Who Killed Don Quixote', `${NS}.Genre`, 'Comedy', 'genres' );
86+
await graphModel.mergeRelationship(transaction, `${NS}.Movie`, 'Fear and Loathing in Las Vegas', `${NS}.Genre`, 'Comedy', 'genres' );
87+
88+
await graphModel.mergeNode(transaction, `${NS}.Director`, {identifier: 'Terry Gilliam'} );
89+
await graphModel.mergeRelationship(transaction, `${NS}.Director`, 'Terry Gilliam', `${NS}.Movie`, 'Brazil', 'directed' );
90+
await graphModel.mergeRelationship(transaction, `${NS}.Director`, 'Terry Gilliam', `${NS}.Movie`, 'The Man Who Killed Don Quixote', 'directed' );
91+
await graphModel.mergeRelationship(transaction, `${NS}.Director`, 'Terry Gilliam', `${NS}.Movie`, 'Fear and Loathing in Las Vegas', 'directed' );
92+
93+
await graphModel.mergeNode(transaction, `${NS}.User`, {identifier: 'Dan', address} );
94+
await graphModel.mergeRelationship(transaction, `${NS}.User`, 'Dan', `${NS}.Movie`, 'Brazil', 'ratedMovies' );
95+
96+
await graphModel.mergeNode(transaction, `${NS}.Actor`, {identifier: 'Jonathan Pryce'} );
97+
await graphModel.mergeRelationship(transaction, `${NS}.Actor`, 'Jonathan Pryce', `${NS}.Movie`, 'Brazil', 'actedIn' );
98+
await graphModel.mergeRelationship(transaction, `${NS}.Actor`, 'Jonathan Pryce', `${NS}.Movie`, 'The Man Who Killed Don Quixote', 'actedIn' );
99+
100+
await graphModel.mergeNode(transaction, `${NS}.Actor`, {identifier: 'Johnny Depp'} );
101+
await graphModel.mergeRelationship(transaction, `${NS}.Actor`, 'Johnny Depp', `${NS}.Movie`, 'Fear and Loathing in Las Vegas', 'actedIn' );
102+
103+
const search = 'Working in a boring job and looking for love.';
104+
const results = await graphModel.similarityQuery(`${NS}.Movie`, 'embedding', search, 3);
88105
console.log(results);
89106
});
90-
await session.close();
107+
await graphModel.closeSession(context);
91108
console.log('done');
92-
return graphModel;
93109
}
94110

95111
run();

0 commit comments

Comments
 (0)