eventregistry 8.9.2 → 8.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -1
- package/dist/eventRegistry.js +2 -2
- package/dist/eventRegistry.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/queryArticles.js +6 -0
- package/dist/queryArticles.js.map +1 -1
- package/dist/queryEvents.js +6 -0
- package/dist/queryEvents.js.map +1 -1
- package/dist/queryMentions.d.ts +95 -0
- package/dist/queryMentions.js +579 -0
- package/dist/queryMentions.js.map +1 -0
- package/dist/topicPage.js +2 -2
- package/dist/topicPage.js.map +1 -1
- package/{src → dist}/types.d.ts +284 -195
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +6 -5
- package/dist/correlations.d.ts +0 -50
- package/dist/correlations.js +0 -397
- package/dist/correlations.js.map +0 -1
- package/examples/autoSuggestionsExamples.ts +0 -46
- package/examples/countsExamples.ts +0 -34
- package/examples/dailySharesExamples.ts +0 -54
- package/examples/eventForTextExamples.ts +0 -32
- package/examples/feedOfNewArticlesExamples.ts +0 -82
- package/examples/feedOfNewEventsExamples.ts +0 -70
- package/examples/queryArticleExamples.ts +0 -42
- package/examples/queryArticlesExamples.ts +0 -242
- package/examples/queryEventExamples.ts +0 -99
- package/examples/queryEventsExamples.ts +0 -232
- package/examples/topicPageExamples.ts +0 -97
- package/examples/trendsExamples.ts +0 -34
- package/src/analytics.ts +0 -181
- package/src/base.ts +0 -198
- package/src/counts.ts +0 -119
- package/src/dailyShares.ts +0 -48
- package/src/eventForText.ts +0 -61
- package/src/eventRegistry.ts +0 -733
- package/src/index.ts +0 -111
- package/src/info.ts +0 -121
- package/src/query.ts +0 -257
- package/src/queryArticle.ts +0 -139
- package/src/queryArticles.ts +0 -603
- package/src/queryEvent.ts +0 -473
- package/src/queryEvents.ts +0 -684
- package/src/queryStory.ts +0 -152
- package/src/recent.ts +0 -63
- package/src/returnInfo.ts +0 -363
- package/src/topicPage.ts +0 -479
- package/src/trends.ts +0 -63
- package/test/index.d.ts +0 -18
- package/test/jasmine.json +0 -10
- package/test/spec/analytics.spec.ts +0 -150
- package/test/spec/autoSuggestions.spec.ts +0 -54
- package/test/spec/info.spec.ts +0 -84
- package/test/spec/invalidQueries.spec.ts +0 -147
- package/test/spec/queryArticle.spec.ts +0 -62
- package/test/spec/queryArticles.spec.ts +0 -541
- package/test/spec/queryArticlesComplex.spec.ts +0 -298
- package/test/spec/queryEvent.spec.ts +0 -194
- package/test/spec/queryEvents.spec.ts +0 -491
- package/test/spec/queryEventsComplex.spec.ts +0 -188
- package/test/spec/queryPaging.spec.ts +0 -318
- package/test/spec/returnInfo.spec.ts +0 -34
- package/test/spec/topicPage.spec.ts +0 -83
- package/test/spec/utils.ts +0 -436
- package/test/tsconfig.json +0 -31
- package/tsconfig.json +0 -32
- package/tslint.json +0 -25
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
|
-
import { Analytics, sleep } from "../../src/index";
|
|
3
|
-
import { Utils } from "./utils";
|
|
4
|
-
|
|
5
|
-
describe("Analytics", () => {
|
|
6
|
-
const er = Utils.initAPI();
|
|
7
|
-
let analytics;
|
|
8
|
-
|
|
9
|
-
beforeAll(() => {
|
|
10
|
-
analytics = new Analytics(er);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("should test text annotation", async (done) => {
|
|
14
|
-
const annInfo = await analytics.annotate("Microsoft released a new version of Windows OS.");
|
|
15
|
-
expect(annInfo).toHaveProperty("annotations");
|
|
16
|
-
expect(_.size(_.get(annInfo, "annotations"))).toEqual(2);
|
|
17
|
-
const ann = _.first(_.get(annInfo, "annotations"));
|
|
18
|
-
expect(ann).toHaveProperty("url");
|
|
19
|
-
expect(ann).toHaveProperty("title");
|
|
20
|
-
expect(ann).toHaveProperty("lang");
|
|
21
|
-
expect(ann).toHaveProperty("secLang");
|
|
22
|
-
expect(ann).toHaveProperty("secUrl");
|
|
23
|
-
expect(ann).toHaveProperty("secTitle");
|
|
24
|
-
expect(ann).toHaveProperty("wgt");
|
|
25
|
-
expect(ann).toHaveProperty("wikiDataItemId");
|
|
26
|
-
expect(annInfo).toHaveProperty("adverbs");
|
|
27
|
-
expect(annInfo).toHaveProperty("adjectives");
|
|
28
|
-
expect(annInfo).toHaveProperty("verbs");
|
|
29
|
-
expect(annInfo).toHaveProperty("nouns");
|
|
30
|
-
expect(annInfo).toHaveProperty("ranges");
|
|
31
|
-
expect(annInfo).toHaveProperty("language");
|
|
32
|
-
done();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should test categorization", async (done) => {
|
|
36
|
-
const response = await analytics.categorize("Microsoft released a new version of Windows OS.");
|
|
37
|
-
expect(response).toHaveProperty("categories");
|
|
38
|
-
for (const category of response["categories"]) {
|
|
39
|
-
expect(category).toHaveProperty("label");
|
|
40
|
-
expect(category).toHaveProperty("score");
|
|
41
|
-
}
|
|
42
|
-
done();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should test sentiment", async (done) => {
|
|
46
|
-
const response = await analytics.sentiment(`
|
|
47
|
-
Residents and tourists enjoy holiday weekend even as waves start to pound; beaches remain closed due to dangerous rip currents.
|
|
48
|
-
Despite a state of emergency declared by the governor and warnings about dangerous surf and the possibility of significant coastal flooding,
|
|
49
|
-
residents and visitors to the Jersey Shore spent Saturday making the most of the calm before the storm. Cloudy skies in the morning gave way to sunshine in the afternoon,
|
|
50
|
-
and despite winds that already were kicking up sand and carving the beach, people flocked to the boardwalk in both Seaside Heights and Point Pleasant Beach, where children rode amusement rides and teens enjoyed ice cream cones.
|
|
51
|
-
`);
|
|
52
|
-
expect(response).toHaveProperty("avgSent");
|
|
53
|
-
expect(response).toHaveProperty("sentimentPerSent");
|
|
54
|
-
done();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("should test language detection", async (done) => {
|
|
58
|
-
const langInfo = await analytics.detectLanguage("Microsoft released a new version of Windows OS.");
|
|
59
|
-
expect(langInfo).toHaveProperty("languages");
|
|
60
|
-
expect(langInfo["languages"][0]).toHaveProperty("code");
|
|
61
|
-
expect(langInfo["languages"][0]).toHaveProperty("name");
|
|
62
|
-
expect(langInfo["languages"][0]).toHaveProperty("percent");
|
|
63
|
-
done();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("should test semantics similarity", async (done) => {
|
|
67
|
-
const doc1 = `
|
|
68
|
-
The editor, Carrie Gracie, who joined the network 30 years ago, said she quit her position as China editor last week to protest pay inequality within the company.
|
|
69
|
-
In the letter posted on her website, she said that she and other women had long suspected their male counterparts drew larger salaries and that BBC management had refused to acknowledge the problem.
|
|
70
|
-
`;
|
|
71
|
-
const doc2 = `
|
|
72
|
-
Paukenschlag bei der britischen BBC: Die China-Expertin Carrie Gracie hat aus Protest gegen die illegale Gehaltskultur und damit verbundene Heimlichtuerei ihren Job bei dem öffentlich-rechtlichen Sender hingeworfen.
|
|
73
|
-
Zwei ihrer männlichen Kollegen in vergleichbaren Positionen würden nachweislich wesentlich besser bezahlt.
|
|
74
|
-
`;
|
|
75
|
-
const info = await analytics.semanticSimilarity(doc1, doc2);
|
|
76
|
-
expect(info).toHaveProperty("similarity");
|
|
77
|
-
done();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("should test article information extraction", async (done) => {
|
|
81
|
-
const info = await analytics.extractArticleInfo("https://www.theguardian.com/world/2018/jan/31/this-is-over-puigdemonts-catalan-independence-doubts-caught-on-camera");
|
|
82
|
-
expect(info).toHaveProperty("title");
|
|
83
|
-
expect(info).toHaveProperty("body");
|
|
84
|
-
expect(info).toHaveProperty("date");
|
|
85
|
-
expect(info).toHaveProperty("datetime");
|
|
86
|
-
expect(info).toHaveProperty("image");
|
|
87
|
-
// there can be other additional properties available, depending on what is available in the article
|
|
88
|
-
done();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("should train topic", async (done) => {
|
|
92
|
-
const response1 = await analytics.trainTopicCreateTopic("my topic2");
|
|
93
|
-
if (_.has(response1, "error")) {
|
|
94
|
-
if (_.parseInt(_.get(response1, "error.response.status")) >= 500) {
|
|
95
|
-
console.error(_.get(response1, "error.message"));
|
|
96
|
-
done();
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
expect(response1).toHaveProperty("uri");
|
|
101
|
-
const uri = response1["uri"];
|
|
102
|
-
// tslint:disable-next-line:max-line-length
|
|
103
|
-
await analytics.trainTopicAddDocument(uri, "Facebook has removed 18 accounts and 52 pages associated with the Myanmar military, including the page of its commander-in-chief, after a UN report accused the armed forces of genocide and war crimes.");
|
|
104
|
-
// tslint:disable-next-line:max-line-length
|
|
105
|
-
await analytics.trainTopicAddDocument(uri, "Emmanuel Macron’s climate commitment to “make this planet great again” has come under attack after his environment minister dramatically quit, saying the French president was not doing enough on climate and other environmental goals.");
|
|
106
|
-
// tslint:disable-next-line:max-line-length
|
|
107
|
-
await analytics.trainTopicAddDocument(uri, "Theresa May claimed that a no-deal Brexit “wouldn’t be the end of the world” as she sought to downplay a controversial warning made by Philip Hammond last week that it would cost £80bn in extra borrowing and inhibit long-term economic growth.");
|
|
108
|
-
// check that we can also get the topic later on
|
|
109
|
-
const response3 = await analytics.trainTopicGetTrainedTopic(uri);
|
|
110
|
-
if (_.has(response3, "error")) {
|
|
111
|
-
if (_.parseInt(_.get(response3, "error.response.status")) >= 500) {
|
|
112
|
-
console.error(_.get(response3, "error.message"));
|
|
113
|
-
done();
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
expect(response3).toHaveProperty("topic");
|
|
118
|
-
const topic2 = response3["topic"];
|
|
119
|
-
expect(topic2).toHaveProperty("concepts");
|
|
120
|
-
expect(_.size(_.get(topic2, "concepts", []))).toBeGreaterThan(0);
|
|
121
|
-
expect(topic2).toHaveProperty("categories");
|
|
122
|
-
expect(_.size(_.get(topic2, "categories", []))).toBeGreaterThan(0);
|
|
123
|
-
done();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
xit("should train topic on twitter", async (done) => {
|
|
127
|
-
const response1 = await analytics.trainTopicOnTweets("@SeanEllis", {maxConcepts: 50, maxCategories: 20, maxTweets: 400});
|
|
128
|
-
if (_.has(response1, "error")) {
|
|
129
|
-
if (_.parseInt(_.get(response1, "error.response.status")) >= 500) {
|
|
130
|
-
console.error(_.get(response1, "error.message"));
|
|
131
|
-
done();
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
expect(response1).toHaveProperty("uri");
|
|
136
|
-
const uri = response1["uri"];
|
|
137
|
-
await sleep(5 * 1000);
|
|
138
|
-
const response2 = await analytics.trainTopicGetTrainedTopic(uri);
|
|
139
|
-
if (_.has(response2, "error")) {
|
|
140
|
-
if (_.parseInt(_.get(response2, "error.response.status")) >= 500) {
|
|
141
|
-
console.error(_.get(response2, "error.message"));
|
|
142
|
-
done();
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
expect(response2).toHaveProperty("topic");
|
|
147
|
-
done();
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
|
-
import { Utils } from "./utils";
|
|
3
|
-
|
|
4
|
-
describe("Auto Suggest", () => {
|
|
5
|
-
const er = Utils.initAPI();
|
|
6
|
-
|
|
7
|
-
it("should return a concept", async (done) => {
|
|
8
|
-
expect(await er.getConceptUri("Obama")).toContain("Barack_Obama");
|
|
9
|
-
done();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("should return a category", async (done) => {
|
|
13
|
-
expect(await er.getCategoryUri("business")).toEqual("dmoz/Business");
|
|
14
|
-
expect(await er.getCategoryUri("birding")).toEqual("dmoz/Recreation/Birding");
|
|
15
|
-
done();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("should return a news source", async (done) => {
|
|
19
|
-
expect(await er.getNewsSourceUri("nytimes")).toEqual("nytimes.com");
|
|
20
|
-
expect(await er.getNewsSourceUri("bbc")).toEqual("bbc.co.uk");
|
|
21
|
-
done();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Highly dependant on the database used.
|
|
25
|
-
xit("should return a pr source", async (done) => {
|
|
26
|
-
expect(await er.getNewsSourceUri("Business Wire")).toEqual("businesswire.com");
|
|
27
|
-
expect(await er.getNewsSourceUri("dailypolitical.com")).toEqual("dailypolitical.com");
|
|
28
|
-
done();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// Highly dependant on the database used.
|
|
32
|
-
xit("should return a blog source", async (done) => {
|
|
33
|
-
expect(await er.getNewsSourceUri("topix.com")).toEqual("topix.com");
|
|
34
|
-
done();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("should return a source from the specified place", async (done) => {
|
|
38
|
-
const sources = await er.suggestSourcesAtPlace(await er.getConceptUri("New York City"));
|
|
39
|
-
expect(_.size(sources)).toBeGreaterThan(0);
|
|
40
|
-
done();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should return a location", async (done) => {
|
|
44
|
-
expect(_.get(_.first(await er.suggestLocations("Washington")), "wikiUri")).toEqual("http://en.wikipedia.org/wiki/Washington_(state)");
|
|
45
|
-
expect(_.get(_.first(await er.suggestLocations("London")), "wikiUri")).toEqual("http://en.wikipedia.org/wiki/London");
|
|
46
|
-
done();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("should return locations from the specified coordinates", async (done) => {
|
|
50
|
-
const locations = await er.suggestLocationsAtCoordinate(38.893352, -77.093779, 300, {limitToCities: true});
|
|
51
|
-
expect(_.size(locations)).toBeGreaterThan(0);
|
|
52
|
-
done();
|
|
53
|
-
});
|
|
54
|
-
});
|
package/test/spec/info.spec.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
|
-
import {
|
|
3
|
-
CategoryInfoFlags,
|
|
4
|
-
ConceptInfoFlags,
|
|
5
|
-
GetCategoryInfo,
|
|
6
|
-
GetConceptInfo,
|
|
7
|
-
GetSourceInfo,
|
|
8
|
-
ReturnInfo,
|
|
9
|
-
SourceInfoFlags,
|
|
10
|
-
} from "../../src/index";
|
|
11
|
-
import { Utils } from "./utils";
|
|
12
|
-
|
|
13
|
-
describe("Info", () => {
|
|
14
|
-
const er = Utils.initAPI();
|
|
15
|
-
|
|
16
|
-
it("should return sources by uri", async (done) => {
|
|
17
|
-
const sources = await er.suggestNewsSources("bbc", {count: 10});
|
|
18
|
-
const sourceUriList = _.map(sources, "uri") as string[];
|
|
19
|
-
const sourceInfoFlags = new SourceInfoFlags({title: true,
|
|
20
|
-
description: true,
|
|
21
|
-
location: true,
|
|
22
|
-
ranking: true,
|
|
23
|
-
});
|
|
24
|
-
const returnInfo = new ReturnInfo({sourceInfo: sourceInfoFlags});
|
|
25
|
-
const q = new GetSourceInfo({uriOrUriList: sourceUriList, returnInfo: returnInfo});
|
|
26
|
-
const response = await er.execQuery(q);
|
|
27
|
-
expect(_.size(response)).toBe(_.size(sourceUriList), `Expected ${_.size(sourceUriList)} sources`);
|
|
28
|
-
_.each(response, (item) => {
|
|
29
|
-
// For some cases backend reports an error attached to a specific source (i.e. 'Provided uri is not valid')
|
|
30
|
-
if (!_.has(item, "error")) {
|
|
31
|
-
expect(_.has(item, "uri")).toBeTruthy(`Source uri is missing for ${JSON.stringify(item)}`);
|
|
32
|
-
expect(_.has(item, "title")).toBeTruthy(`Source title is missing for ${JSON.stringify(item)}`);
|
|
33
|
-
expect(_.has(item, "description")).toBeTruthy(`Source description is missing for ${JSON.stringify(item)}`);
|
|
34
|
-
expect(_.has(item, "ranking")).toBeTruthy(`Source ranking is missing for ${JSON.stringify(item)}`);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
done();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("should return concepts by uri", async (done) => {
|
|
41
|
-
const concepts = await er.suggestConcepts("a", {count: 10});
|
|
42
|
-
const uriList = _.map(concepts, "uri") as string[];
|
|
43
|
-
const conceptInfoFlags = new ConceptInfoFlags({type: "wiki",
|
|
44
|
-
lang: ["deu", "slv"],
|
|
45
|
-
label: true,
|
|
46
|
-
synonyms: true,
|
|
47
|
-
image: true,
|
|
48
|
-
description: true,
|
|
49
|
-
trendingScore: true,
|
|
50
|
-
});
|
|
51
|
-
const returnInfo = new ReturnInfo({conceptInfo: conceptInfoFlags});
|
|
52
|
-
const q = new GetConceptInfo({uriOrUriList: uriList, returnInfo: returnInfo});
|
|
53
|
-
const response = await er.execQuery(q);
|
|
54
|
-
expect(_.size(response)).toBe(_.size(uriList), `Expected ${_.size(uriList)} concepts`);
|
|
55
|
-
_.each(response, (item) => {
|
|
56
|
-
expect(_.has(item, "uri")).toBeTruthy("Concept uri is missing");
|
|
57
|
-
expect(_.has(item, "type")).toBeTruthy("Concept type is missing");
|
|
58
|
-
expect(_.has(item, "label")).toBeTruthy("Concept should have a label");
|
|
59
|
-
expect(_.has(item, "label.deu")).toBeTruthy("Concept should have a label in german");
|
|
60
|
-
expect(_.has(item, "label.slv")).toBeTruthy("Concept should have a label in slovene");
|
|
61
|
-
expect(_.has(item, "description")).toBeTruthy("Concept should have a description");
|
|
62
|
-
expect(_.has(item, "image")).toBeTruthy("Concept should have an image");
|
|
63
|
-
expect(_.has(item, "synonyms")).toBeTruthy("Concept should have synonyms");
|
|
64
|
-
expect(_.has(item, "trendingScore")).toBeTruthy("Concept should have trendingScore");
|
|
65
|
-
});
|
|
66
|
-
done();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("should return categories", async (done) => {
|
|
70
|
-
const categories = await er.suggestCategories("a", {count: 10});
|
|
71
|
-
const uriList = _.map(categories, "uri") as string[];
|
|
72
|
-
const categoryInfoFlags = new CategoryInfoFlags({ trendingScore: true });
|
|
73
|
-
const returnInfo = new ReturnInfo({categoryInfo: categoryInfoFlags});
|
|
74
|
-
const q = new GetCategoryInfo({uriOrUriList: uriList, returnInfo: returnInfo});
|
|
75
|
-
const response = await er.execQuery(q);
|
|
76
|
-
expect(_.size(response)).toBe(_.size(uriList), `Expected ${_.size(uriList)} categories`);
|
|
77
|
-
_.each(response, (item) => {
|
|
78
|
-
if (_.has(item, "error")) return;
|
|
79
|
-
expect(_.has(item, "uri")).toBeTruthy("Category uri is missing");
|
|
80
|
-
expect(_.has(item, "trendingScore")).toBeTruthy("Category trending score is missing");
|
|
81
|
-
});
|
|
82
|
-
done();
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
|
-
import { QueryArticles } from "../../src";
|
|
3
|
-
import { Utils } from "./utils";
|
|
4
|
-
|
|
5
|
-
describe("Invalid queries", () => {
|
|
6
|
-
const er = Utils.initAPI();
|
|
7
|
-
const utils = new Utils();
|
|
8
|
-
it("should test produce an error on an invalid query", async (done) => {
|
|
9
|
-
const bushUri = await er.getConceptUri("Bush");
|
|
10
|
-
const obamaUri = await er.getConceptUri("Obama");
|
|
11
|
-
const politicsUri = await er.getCategoryUri("politics");
|
|
12
|
-
const merkelUri = await er.getConceptUri("merkel");
|
|
13
|
-
const businessUri = await er.getCategoryUri("business");
|
|
14
|
-
|
|
15
|
-
const qStr1 = `
|
|
16
|
-
{
|
|
17
|
-
"$query": {
|
|
18
|
-
"$or": [
|
|
19
|
-
{ "dateStart": "2017-02-05", "dateEnd": "2017-02-05" },
|
|
20
|
-
{ "conceptUri": "${bushUri}" },
|
|
21
|
-
{ "categoryUri": "${politicsUri}" },
|
|
22
|
-
{
|
|
23
|
-
"$and": [
|
|
24
|
-
{ "conceptUri": "${merkelUri}" },
|
|
25
|
-
{ "categoryUri": "${businessUri}" }
|
|
26
|
-
]
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
"$not": {
|
|
30
|
-
"$or": [
|
|
31
|
-
{ "dateStart": "2017-02-04", "dateEnd": "2017-02-04" },
|
|
32
|
-
{ "conceptUri": "${obamaUri}" }
|
|
33
|
-
]
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
`;
|
|
38
|
-
const q1 = QueryArticles.initWithComplexQuery(qStr1);
|
|
39
|
-
const response1 = await er.execQuery(q1);
|
|
40
|
-
expect(_.has(response1, "error")).toBeFalsy();
|
|
41
|
-
|
|
42
|
-
const qStr2 = `
|
|
43
|
-
{
|
|
44
|
-
"$query": {
|
|
45
|
-
"$or": [
|
|
46
|
-
{ "conceptUri": "${bushUri}" },
|
|
47
|
-
{ "categoryUri": "${politicsUri}" }
|
|
48
|
-
],
|
|
49
|
-
"$not": {
|
|
50
|
-
"$or": [
|
|
51
|
-
]
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
`;
|
|
56
|
-
const q2 = new QueryArticles();
|
|
57
|
-
q2.setVal("query", qStr2);
|
|
58
|
-
const response2 = await er.execQuery(q2);
|
|
59
|
-
expect(_.has(response2, "error")).toBeTruthy();
|
|
60
|
-
|
|
61
|
-
const qStr3 = `
|
|
62
|
-
{
|
|
63
|
-
"$query": {
|
|
64
|
-
"$or": [
|
|
65
|
-
{ "conceptUri": "${bushUri}" },
|
|
66
|
-
{ "categoryUri": "${politicsUri}" }
|
|
67
|
-
],
|
|
68
|
-
"$not": {
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
`;
|
|
73
|
-
const q3 = new QueryArticles();
|
|
74
|
-
q3.setVal("query", qStr3);
|
|
75
|
-
const response3 = await er.execQuery(q3);
|
|
76
|
-
expect(_.has(response3, "error")).toBeTruthy();
|
|
77
|
-
|
|
78
|
-
const qStr4 = `
|
|
79
|
-
{
|
|
80
|
-
"$query": {
|
|
81
|
-
"$aaaaor": [
|
|
82
|
-
{ "conceptUri": "${bushUri}" },
|
|
83
|
-
{ "categoryUri": "${politicsUri}" }
|
|
84
|
-
],
|
|
85
|
-
"$not": {
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
`;
|
|
90
|
-
const q4 = new QueryArticles();
|
|
91
|
-
q4.setVal("query", qStr4);
|
|
92
|
-
const response4 = await er.execQuery(q4);
|
|
93
|
-
expect(_.has(response4, "error")).toBeTruthy();
|
|
94
|
-
|
|
95
|
-
const qStr5 = `
|
|
96
|
-
{
|
|
97
|
-
"$query": {
|
|
98
|
-
"$and": [
|
|
99
|
-
],
|
|
100
|
-
"$not": {
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
`;
|
|
105
|
-
const q5 = new QueryArticles();
|
|
106
|
-
q5.setVal("query", qStr5);
|
|
107
|
-
const response5 = await er.execQuery(q5);
|
|
108
|
-
expect(_.has(response5, "error")).toBeTruthy();
|
|
109
|
-
|
|
110
|
-
const qStr6 = `
|
|
111
|
-
{
|
|
112
|
-
"$query": {
|
|
113
|
-
"$and": [
|
|
114
|
-
]
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
`;
|
|
118
|
-
const q6 = new QueryArticles();
|
|
119
|
-
q6.setVal("query", qStr6);
|
|
120
|
-
const response6 = await er.execQuery(q6);
|
|
121
|
-
expect(_.has(response6, "error")).toBeTruthy();
|
|
122
|
-
|
|
123
|
-
const qStr7 = `
|
|
124
|
-
{
|
|
125
|
-
"$query": {
|
|
126
|
-
"$and": {}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
`;
|
|
130
|
-
const q7 = new QueryArticles();
|
|
131
|
-
q7.setVal("query", qStr7);
|
|
132
|
-
const response7 = await er.execQuery(q7);
|
|
133
|
-
expect(_.has(response7, "error")).toBeTruthy();
|
|
134
|
-
|
|
135
|
-
const qStr8 = `
|
|
136
|
-
{
|
|
137
|
-
"$query": {
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
`;
|
|
141
|
-
const q8 = new QueryArticles();
|
|
142
|
-
q8.setVal("query", qStr8);
|
|
143
|
-
const response8 = await er.execQuery(q8);
|
|
144
|
-
expect(_.has(response8, "error")).toBeTruthy();
|
|
145
|
-
done();
|
|
146
|
-
});
|
|
147
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
|
-
import {
|
|
3
|
-
ArticleMapper,
|
|
4
|
-
EventRegistry,
|
|
5
|
-
QueryArticle,
|
|
6
|
-
QueryArticles,
|
|
7
|
-
RequestArticleInfo,
|
|
8
|
-
RequestArticlesUriWgtList,
|
|
9
|
-
} from "../../src/index";
|
|
10
|
-
import { Utils } from "./utils";
|
|
11
|
-
|
|
12
|
-
describe("Query Article", () => {
|
|
13
|
-
const er = Utils.initAPI();
|
|
14
|
-
const utils = new Utils();
|
|
15
|
-
let query;
|
|
16
|
-
|
|
17
|
-
beforeAll(async (done) => {
|
|
18
|
-
const q = new QueryArticles({conceptUri: await er.getConceptUri("Obama")});
|
|
19
|
-
const requestArticlesUriWgtList = new RequestArticlesUriWgtList({count: 10});
|
|
20
|
-
q.setRequestedResult(requestArticlesUriWgtList);
|
|
21
|
-
const response = await er.execQuery(q);
|
|
22
|
-
query = new QueryArticle(EventRegistry.getUriFromUriWgt(_.get(response, "uriWgtList.results")));
|
|
23
|
-
done();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should return articles", async (done) => {
|
|
27
|
-
const requestArticleInfo = new RequestArticleInfo(utils.returnInfo);
|
|
28
|
-
query.setRequestedResult(requestArticleInfo);
|
|
29
|
-
const response = await er.execQuery(query);
|
|
30
|
-
expect(_.size(response)).toBeGreaterThan(0, "Expected to get a list of more than 0 articles");
|
|
31
|
-
_.each(response, (article) => {
|
|
32
|
-
expect(article.info).toBeValidArticle();
|
|
33
|
-
});
|
|
34
|
-
const uris = _.map(response, (item) => _.get(item, "info.uri"));
|
|
35
|
-
const urls = _.map(response, (item) => _.get(item, "info.url"));
|
|
36
|
-
const uniqueUrls = _.uniq(urls);
|
|
37
|
-
const mapper = new ArticleMapper(er);
|
|
38
|
-
const mappedUris = await Promise.all(_.map(uniqueUrls, (url) => mapper.getArticleUri(url)));
|
|
39
|
-
if (!_.isEmpty(_.compact(mappedUris))) {
|
|
40
|
-
const q = new QueryArticle(_.compact(mappedUris));
|
|
41
|
-
q.setRequestedResult(new RequestArticleInfo(utils.returnInfo));
|
|
42
|
-
const res = await er.execQuery(q);
|
|
43
|
-
_.each(res, (article) => {
|
|
44
|
-
// it's possible that the article was removed from ER
|
|
45
|
-
if (!_.has(article, "error")) {
|
|
46
|
-
expect(article["info"]).toBeValidArticle();
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
const q1 = new QueryArticle(uris);
|
|
51
|
-
q1.setRequestedResult(new RequestArticleInfo(utils.returnInfo));
|
|
52
|
-
const res1 = await er.execQuery(q1);
|
|
53
|
-
expect(_.size(res1)).toBeGreaterThan(0, "Expected to get a list of more than 0 articles when searching by uris");
|
|
54
|
-
_.each(res1, (article) => {
|
|
55
|
-
// it's possible that the article was removed from ER
|
|
56
|
-
if (!_.has(article, "error")) {
|
|
57
|
-
expect(article["info"]).toBeValidArticle();
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
done();
|
|
61
|
-
});
|
|
62
|
-
});
|