-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
...ntegration/pi_network/PiComply/src/regulatory-knowledge-graph/RegulatoryKnowledgeGraph.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { GraphQLSchema } from "graphql"; | ||
import { Neo4jDriver } from "neo4j-driver"; | ||
import { RDFStore } from "rdf-store"; | ||
import { Ontology } from "../ontology/Ontology"; | ||
import { Reasoner } from "../reasoner/Reasoner"; | ||
|
||
class RegulatoryKnowledgeGraph { | ||
constructor(neo4jDriver, rdfStore, ontology, reasoner) { | ||
this.neo4jDriver = neo4jDriver; | ||
this.rdfStore = rdfStore; | ||
this.ontology = ontology; | ||
this.reasoner = reasoner; | ||
this.graphQLSchema = new GraphQLSchema({ | ||
typeDefs: ` | ||
type ComplianceRule { | ||
id: ID! | ||
description: String! | ||
regulatoryText: String! | ||
applicableTo: [String!]! | ||
} | ||
type ComplianceResult { | ||
id: ID! | ||
ruleId: ID! | ||
status: String! | ||
data: String! | ||
} | ||
type Query { | ||
complianceRules: [ComplianceRule!]! | ||
complianceResults(ruleId: ID!): [ComplianceResult!]! | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
complianceRules: async () => { | ||
const results = await this.neo4jDriver.cypher("MATCH (n:ComplianceRule) RETURN n"); | ||
return results.records.map((record) => record.get("n").properties); | ||
}, | ||
complianceResults: async (parent, { ruleId }) => { | ||
const results = await this.neo4jDriver.cypher("MATCH (n:ComplianceResult { ruleId: $ruleId }) RETURN n", { ruleId }); | ||
return results.records.map((record) => record.get("n").properties); | ||
}, | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
async init() { | ||
// Initialize Neo4j driver | ||
await this.neo4jDriver.init(); | ||
|
||
// Initialize RDF store | ||
await this.rdfStore.init(); | ||
|
||
// Initialize ontology | ||
await this.ontology.init(); | ||
|
||
// Initialize reasoner | ||
await this.reasoner.init(); | ||
} | ||
|
||
async addComplianceRule(rule) { | ||
// Add compliance rule to Neo4j graph | ||
await this.neo4jDriver.cypher("CREATE (n:ComplianceRule { id: $id, description: $description, regulatoryText: $regulatoryText, applicableTo: $applicableTo })", rule); | ||
|
||
// Add compliance rule to RDF store | ||
await this.rdfStore.addTriple(rule.id, "http://example.com/ontology#description", rule.description); | ||
await this.rdfStore.addTriple(rule.id, "http://example.com/ontology#regulatoryText", rule.regulatoryText); | ||
await this.rdfStore.addTriple(rule.id, "http://example.com/ontology#applicableTo", rule.applicableTo); | ||
|
||
// Reason over the graph to infer new relationships | ||
await this.reasoner.reason(); | ||
} | ||
|
||
async addComplianceResult(result) { | ||
// Add compliance result to Neo4j graph | ||
await this.neo4jDriver.cypher("CREATE (n:ComplianceResult { id: $id, ruleId: $ruleId, status: $status, data: $data })", result); | ||
|
||
// Add compliance result to RDF store | ||
await this.rdfStore.addTriple(result.id, "http://example.com/ontology#ruleId", result.ruleId); | ||
await this.rdfStore.addTriple(result.id, "http://example.com/ontology#status", result.status); | ||
await this.rdfStore.addTriple(result.id, "http://example.com/ontology#data", result.data); | ||
} | ||
|
||
async queryGraphQL(query) { | ||
return this.graphQLSchema.execute(query); | ||
} | ||
} | ||
|
||
export { RegulatoryKnowledgeGraph }; |