wiki-entity 0.5.0 → 0.5.4
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/README.md
CHANGED
|
@@ -24,8 +24,8 @@ Gets entities from wikidata and wikipedia.
|
|
|
24
24
|
|
|
25
25
|
Required. `ids` or `titles` require. Params properties:
|
|
26
26
|
|
|
27
|
-
- **ids** :*string[]* - wikidata ids; (max
|
|
28
|
-
- **titles** :*string[]* - wikipedia article titles; (max
|
|
27
|
+
- **ids** :*string[]* - wikidata ids; (max 500)
|
|
28
|
+
- **titles** :*string[]* - wikipedia article titles; (max 500)
|
|
29
29
|
- **language** :*string* - language of `titles` param and of the result object info; default: `en`
|
|
30
30
|
- **props** :*string[]* - entity props to get. Can by: `info`|`sitelinks`|`aliases`|`labels`|`descriptions`|`claims`|`datatype`;
|
|
31
31
|
- **claims** :*string* - How to resolve the claims. Can be: `none`, `all`, `item`, `property`. Default: `none`. `all` resolves `item` and `property` types.
|
|
@@ -16,7 +16,7 @@ function convertToSimpleEntity(wikiEntity, lang, options) {
|
|
|
16
16
|
entity.wikiPageId = wikiEntity.pageid;
|
|
17
17
|
entity.about = wikiEntity.extract;
|
|
18
18
|
if (wikiEntity.types) {
|
|
19
|
-
entity.types = utils_1.uniq(wikiEntity.types.filter(item => !/:(Thing|Agent)$/.test(item)));
|
|
19
|
+
entity.types = utils_1.uniq(wikiEntity.types.filter((item) => !/:(Thing|Agent)$/.test(item)));
|
|
20
20
|
}
|
|
21
21
|
entity.type = getEntityType_1.getEntityType(wikiEntity);
|
|
22
22
|
if (!entity.type) {
|
|
@@ -42,10 +42,6 @@ function convertToSimpleEntity(wikiEntity, lang, options) {
|
|
|
42
42
|
return entity;
|
|
43
43
|
}
|
|
44
44
|
exports.convertToSimpleEntity = convertToSimpleEntity;
|
|
45
|
-
function createAliases(entity) {
|
|
46
|
-
let aliases = entity.aliases || [];
|
|
47
|
-
return utils_1.uniq(aliases);
|
|
48
|
-
}
|
|
49
45
|
function createCategories(entity) {
|
|
50
46
|
let categories = entity.categories || [];
|
|
51
47
|
return utils_1.uniq(categories);
|
package/lib/wikidata/api.js
CHANGED
|
@@ -27,15 +27,13 @@ function getEntities(params) {
|
|
|
27
27
|
types_1.WikidataPropsParam.claims,
|
|
28
28
|
types_1.WikidataPropsParam.datatype
|
|
29
29
|
]).join("|"),
|
|
30
|
-
languages: params.languages
|
|
31
|
-
? params.languages.join("|")
|
|
32
|
-
: params.language || "en",
|
|
30
|
+
languages: params.languages,
|
|
33
31
|
redirects: params.redirect || "yes",
|
|
34
32
|
format: "json",
|
|
35
33
|
sites: ""
|
|
36
34
|
};
|
|
37
35
|
if (params.titles) {
|
|
38
|
-
qs.sites =
|
|
36
|
+
qs.sites = (params.language || "en") + "wiki";
|
|
39
37
|
}
|
|
40
38
|
else {
|
|
41
39
|
delete qs.sites;
|
|
@@ -64,7 +62,7 @@ function getManyEntities(params) {
|
|
|
64
62
|
const max = 50;
|
|
65
63
|
const countParts = keyValues.length / max + 1;
|
|
66
64
|
const parts = [];
|
|
67
|
-
for (var i = 0; i < countParts && i <
|
|
65
|
+
for (var i = 0; i < countParts && i < 10; i++) {
|
|
68
66
|
const partParams = Object.assign({}, params);
|
|
69
67
|
partParams[keyName] = keyValues.slice(i * max, (i + 1) * max);
|
|
70
68
|
if (partParams[keyName].length > 0) {
|
|
@@ -36,7 +36,7 @@ function dbpediaTypes(name) {
|
|
|
36
36
|
const query = `
|
|
37
37
|
SELECT ?type
|
|
38
38
|
WHERE {
|
|
39
|
-
<http://dbpedia.org/resource/${name.replace(/\s+/g, "_")}> rdf:type ?type
|
|
39
|
+
<http://dbpedia.org/resource/${encodeURIComponent(name.replace(/\s+/g, "_"))}> rdf:type ?type
|
|
40
40
|
}`;
|
|
41
41
|
return request_1.default("http://dbpedia.org/sparql", {
|
|
42
42
|
params: { query: query },
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SimpleEntityType, SimpleEntity } from
|
|
2
|
-
import { WikiEntity } from
|
|
1
|
+
import { SimpleEntityType, SimpleEntity } from "./simpleEntity";
|
|
2
|
+
import { WikiEntity } from "../types";
|
|
3
3
|
export declare type WikiEntityToEntityOptions = {
|
|
4
4
|
defaultType?: SimpleEntityType;
|
|
5
5
|
};
|