Skip to content

Commit

Permalink
Merge pull request #28 from leibatt/leilani
Browse files Browse the repository at this point in the history
Leilani
  • Loading branch information
leibatt authored Nov 14, 2022
2 parents 16fcbac + 84de24d commit 9a8531c
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 122 deletions.
8 changes: 3 additions & 5 deletions examples/use_cases/amar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const qualityConcept: pyxis.Concept = new pyxis.Concept(

// We create a knowledge node representing our understanding of how film length
// may affect quality or not.
const biArticle: pyxis.Instance = new pyxis.Instance(
const knowledgeNode: pyxis.DomainKnowledgeNode = new pyxis.DomainKnowledgeNode(
"BusinessInsiderArticle", // name
articleConcept, // coreConcept
[qualityConcept], // relevantConcepts
Expand All @@ -30,10 +30,6 @@ const biArticle: pyxis.Instance = new pyxis.Instance(
id: "dr-bi-mv-ln"
}
);
const knowledgeNode: pyxis.DomainKnowledgeNode = new pyxis.DomainKnowledgeNode(
"BusinessInsiderArticle", // name
biArticle // instance
);

// To investigate evidence, we will use the movies dataset and oscars dataset
// in this example (see README for source details).
Expand Down Expand Up @@ -156,3 +152,5 @@ const movieInsight: pyxis.InsightNode = new pyxis.InsightNode(
"connecting what was learned in an article with movies data" // description
);
console.log(movieInsight);

//pyxis.writeJsonFile(winnersInfo.records.map((d: pyxis.BaseDataRecord) => pyxis.dataRecordToJson(d)),"winners_info.json");
14 changes: 4 additions & 10 deletions examples/use_cases/mathisen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ const protest: pyxis.Concept = new pyxis.Concept(
"Protest", // name
[] // parentConcepts
);
const protestsInstance: pyxis.Instance = new pyxis.Instance(

const protestsNode: pyxis.DomainKnowledgeNode = new pyxis.DomainKnowledgeNode(
"WikipediaArticle-2015BaltimoreProtests", // name
protest, // coreConcept
[], // relevantConcepts
Expand All @@ -83,10 +84,7 @@ const protestsInstance: pyxis.Instance = new pyxis.Instance(
id: "dr-2015-baltimore-protests"
}
);
const protestsNode: pyxis.DomainKnowledgeNode = new pyxis.DomainKnowledgeNode(
"WikipediaArticle-2015BaltimoreProtests", // name
protestsInstance
);

// Now we can link our protests knowledge node with our evidence:
const protestsInsight: pyxis.InsightNode = new pyxis.InsightNode(
"mathisen2019insight1", // name
Expand Down Expand Up @@ -180,7 +178,7 @@ console.log(crimeDist.records[0]);

// Since we find that Burglary was the most common crime, and unusually so, we
// want to incorporate this information in our knowledge base.
const burglaryInstance: pyxis.Instance = new pyxis.Instance(
const burglaryNode: pyxis.DomainKnowledgeNode = new pyxis.DomainKnowledgeNode(
"WikipediaArticle-Burglary", // name
crime, // coreConcept
[], // relevantConcepts
Expand All @@ -190,10 +188,6 @@ const burglaryInstance: pyxis.Instance = new pyxis.Instance(
id: "dr-burglary"
}
);
const burglaryNode: pyxis.DomainKnowledgeNode = new pyxis.DomainKnowledgeNode(
"WikipediaArticle-Burglary", // name
burglaryInstance
);
burglaryNode.addSource(protestsNode);
const burglaryInsight: pyxis.InsightNode = new pyxis.InsightNode(
"mathisen2019insight2", // name
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
"build": "yarn build-src && yarn build-examples && yarn build-datasets",
"build-src": "tsc",
"build-examples": "tsc -p examples/tsconfig.json",
"build-datasets": "unzip datasets/birdstrikes.json.zip ; cp -R datasets build-test",
"build-datasets": "unzip datasets/birdstrikes.json.zip ; mv birdstrikes.json datasets ; cp -R datasets build-test",
"test": "jest --collectCoverage=true && yarn lint",
"lint": "eslint .",
"bundle": "rollup --config"
},
"dependencies": {
"arquero": "^4.8.8",
"isolation-forest": "^0.0.9",
"minimatch": "^3.0.5",
"ml-cart": "^2.1.1",
"ml-knn": "^3.0.0",
"ml-naivebayes": "^4.0.0",
Expand Down
17 changes: 4 additions & 13 deletions src/knowledge/DomainKnowledge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ export class Concept {
}
}

// instances are instantiations of concepts
export class Instance {
name: string; // also acts as a unique identifier
// Domain Knowledge Nodes are instantiations of concepts
export class DomainKnowledgeNode extends GraphNode {
coreConcept: Concept; // main Concept type associated with this instance
relevantConcepts?: Concept[]; // other relevant concepts !== coreConcept
metadata?: DataRecord; // associated metadata attributes for this instance and their values

constructor(name: string, coreConcept: Concept, relevantConcepts?: Concept[], metadata?: DataRecord) {
super(name);
this.name = name;

this.coreConcept = coreConcept;
if(typeof relevantConcepts !== 'undefined') {
this.relevantConcepts = relevantConcepts;
Expand All @@ -38,16 +39,6 @@ export class Instance {
this.metadata = metadata
}
}
}

export class DomainKnowledgeNode extends GraphNode {
instance: Instance; // the instance associated with this domain knowledge

constructor(name: string, instance: Instance) {
super(name);
this.name = name;
this.instance = instance;
}

addTarget<NodeType extends DomainKnowledgeNode>(node: NodeType): void {
super.addTarget(node);
Expand Down
4 changes: 2 additions & 2 deletions src/knowledge/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DomainKnowledgeNode, Concept, Instance } from './DomainKnowledge';
import { DomainKnowledgeNode, Concept } from './DomainKnowledge';
import { AnalyticKnowledgeNode } from './AnalyticKnowledge';

export { DomainKnowledgeNode, Concept, Instance, AnalyticKnowledgeNode };
export { DomainKnowledgeNode, Concept, AnalyticKnowledgeNode };
7 changes: 3 additions & 4 deletions test/insight.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import { Concept, Instance, DomainKnowledgeNode } from '../src/knowledge/DomainKnowledge';
import { Concept, DomainKnowledgeNode } from '../src/knowledge/DomainKnowledge';
import { loadJsonFile } from '../src/load';
import { AttributeType, ValueType, BaseDataset, jsonObjectToDataset } from '../src/dataset';
import { AnalyticKnowledgeNode } from '../src/knowledge/AnalyticKnowledge';
Expand Down Expand Up @@ -27,8 +27,8 @@ describe('insight.ts tests', () => {
id: "d"
}
);
const instance: Instance = new Instance(
"ti1",
const dk = new DomainKnowledgeNode(
"n1",
concept,
[],
{
Expand All @@ -42,7 +42,6 @@ describe('insight.ts tests', () => {
id: "0"
}
);
const dk = new DomainKnowledgeNode("n1",instance);
const t: ArqueroDataTransformation = { // transformation for testing
sources: [cars],
ops: ["filter"],
Expand Down
100 changes: 30 additions & 70 deletions test/knowledge/DomainKnowledge.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Concept, Instance, DomainKnowledgeNode } from '../../src/knowledge/DomainKnowledge';
import { Concept, DomainKnowledgeNode } from '../../src/knowledge/DomainKnowledge';
import { AttributeType } from '../../src/dataset';

describe('DomainKnowledge.ts tests', () => {
Expand All @@ -21,10 +21,25 @@ describe('DomainKnowledge.ts tests', () => {
expect(concept.name).toBe("test concept");
});
});
describe('Instance', () => {
describe('DomainKnowledgeNode', () => {
const concept: Concept = new Concept(
"test concept",
[],
{
attributes: [
{
name: "a",
attributeType: AttributeType.nominal
}
],
values: {"a": "test"},
id: "d"
}
);
test('#constructor works', () => {
const concept: Concept = new Concept(
"test concept",
const node1 = new DomainKnowledgeNode(
"n1",
concept,
[],
{
attributes: [
Expand All @@ -33,84 +48,29 @@ describe('DomainKnowledge.ts tests', () => {
attributeType: AttributeType.nominal
}
],
values: {"a": "test"},
id: "d"
values: {"a": "test1"},
id: "0"
}
);
const instance: Instance = new Instance(
"test instance", // name
concept, // coreConcept
[], // relevantConcepts
{ // metadata
const node2 = new DomainKnowledgeNode(
"n2",
concept,
[],
{
attributes: [
{
name: "a",
attributeType: AttributeType.nominal
}
],
values: {"a": "test"},
id: "d"
values: {"a": "test2"},
id: "1"
}
);
expect(instance.name).toBe("test instance");
});
});
describe('DomainKnowledgeNode', () => {
const concept: Concept = new Concept(
"test concept",
[],
{
attributes: [
{
name: "a",
attributeType: AttributeType.nominal
}
],
values: {"a": "test"},
id: "d"
}
);
const instance: Instance = new Instance(
"ti1",
concept,
[],
{
attributes: [
{
name: "a",
attributeType: AttributeType.nominal
}
],
values: {"a": "test1"},
id: "0"
}
);
const instance2: Instance = new Instance(
"ti2",
concept,
[],
{
attributes: [
{
name: "a",
attributeType: AttributeType.nominal
}
],
values: {"a": "test2"},
id: "1"
}
);
test('#constructor works', () => {
const node1 = new DomainKnowledgeNode("n1",
instance,
);
const node2 = new DomainKnowledgeNode("n2",
instance2,
);
expect(node1.name).toBe("n1");
expect(node1.instance.name).toBe("ti1");
expect(node1.coreConcept.name).toBe("test concept");
expect(node2.name).toBe("n2");
expect(node2.instance.name).toBe("ti2");
expect(node2.coreConcept.name).toBe("test concept");
});
});
});
Expand Down
31 changes: 15 additions & 16 deletions test/task.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import { SimpleTaskNode } from '../src/task';
import { Concept, Instance, DomainKnowledgeNode } from '../src/knowledge/DomainKnowledge';
import { Concept, DomainKnowledgeNode } from '../src/knowledge/DomainKnowledge';
import { loadJsonFile } from '../src/load';
import { AttributeType, ValueType, BaseDataset, jsonObjectToDataset } from '../src/dataset';
import { AnalyticKnowledgeNode } from '../src/knowledge/AnalyticKnowledge';
Expand Down Expand Up @@ -28,22 +28,21 @@ describe('task.ts tests', () => {
id: "d"
}
);
const instance: Instance = new Instance(
"ti1",
concept,
[],
{
attributes: [
{
name: "a",
attributeType: AttributeType.nominal
}
],
values: {"a": "test1"},
id: "0"
}
const dk = new DomainKnowledgeNode(
"n1",
concept,
[],
{
attributes: [
{
name: "a",
attributeType: AttributeType.nominal
}
],
values: {"a": "test1"},
id: "0"
}
);
const dk = new DomainKnowledgeNode("n1",instance);
const t: ArqueroDataTransformation = { // transformation for testing
sources: [cars],
ops: ["filter"],
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3342,7 +3342,7 @@ minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"

minimatch@^3.1.1:
minimatch@^3.0.5, minimatch@^3.1.1:
version "3.1.2"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==
Expand Down

0 comments on commit 9a8531c

Please sign in to comment.