Skip to content

Commit

Permalink
Merge pull request #47 from rikirenz/arxiv-inspire-ext-categ
Browse files Browse the repository at this point in the history
Remove external categories and refactor/simplify inspire ones.
  • Loading branch information
david-caro committed Dec 8, 2016
2 parents 041fa93 + 04f2fc6 commit 5c05db1
Show file tree
Hide file tree
Showing 16 changed files with 1,381 additions and 1,902 deletions.
15 changes: 6 additions & 9 deletions inspire_schemas/records/authors.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,20 @@
"type": "array",
"uniqueItems": true
},
"external_field_categories": {
"items": {
"$ref": "elements/external_field.json"
},
"type": "array",
"uniqueItems": true
},
"ids": {
"items": {
"$ref": "elements/id.json"
},
"type": "array",
"uniqueItems": true
},
"inspire_field_categories": {
"inspire_categories": {
"items": {
"$ref": "elements/inspire_field.json"
"oneOf": [
{
"$ref": "elements/inspire_field.json"
}
]
},
"type": "array",
"uniqueItems": true
Expand Down
15 changes: 6 additions & 9 deletions inspire_schemas/records/conferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,13 @@
"deleted": {
"type": "boolean"
},
"external_field_categories": {
"inspire_categories": {
"items": {
"$ref": "elements/external_field.json"
},
"type": "array",
"uniqueItems": true
},
"inspire_field_categories": {
"items": {
"$ref": "elements/inspire_field.json"
"oneOf": [
{
"$ref": "elements/inspire_field.json"
}
]
},
"type": "array",
"uniqueItems": true
Expand Down
72 changes: 0 additions & 72 deletions inspire_schemas/records/elements/external_field.json

This file was deleted.

50 changes: 29 additions & 21 deletions inspire_schemas/records/elements/inspire_field.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
{
"$schema": "http://json-schema.org/schema#",
"properties": {
"term": {
"enum": [
"Accelerators",
"Astrophysics",
"Computing",
"Data Analysis and Statistics",
"Experiment-HEP",
"Experiment-Nucl",
"General Physics",
"Gravitation and Cosmology",
"Instrumentation",
"Lattice",
"Math and Math Physics",
"Other",
"Phenomenology-HEP",
"Theory-HEP",
"Theory-Nucl"
],
"type": "string"
}
"source": {
"enum": [
"curator",
"magpie",
"arxiv",
"user",
"undefined"
],
"type": "string"
},
"term": {
"enum": [
"Accelerators",
"Astrophysics",
"Computing",
"Data Analysis and Statistics",
"Experiment-HEP",
"Experiment-Nucl",
"General Physics",
"Gravitation and Cosmology",
"Instrumentation",
"Lattice",
"Math and Math Physics",
"Other",
"Phenomenology-HEP",
"Theory-HEP",
"Theory-Nucl"
],
"type": "string"
}
}
15 changes: 6 additions & 9 deletions inspire_schemas/records/experiments.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@
"type": "array",
"uniqueItems": true
},
"external_field_categories": {
"items": {
"$ref": "elements/external_field.json"
},
"type": "array",
"uniqueItems": true
},
"free_keywords": {
"items": {
"title": "Free keyword",
Expand All @@ -112,9 +105,13 @@
"title": "Hidden note",
"type": "string"
},
"inspire_field_categories": {
"inspire_categories": {
"items": {
"$ref": "elements/inspire_field.json"
"oneOf": [
{
"$ref": "elements/inspire_field.json"
}
]
},
"type": "array",
"uniqueItems": true
Expand Down
15 changes: 6 additions & 9 deletions inspire_schemas/records/hep.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,6 @@
},
"type": "array"
},
"external_field_categories": {
"items": {
"$ref": "elements/external_field.json"
},
"type": "array",
"uniqueItems": true
},
"external_system_numbers": {
"items": {
"properties": {
Expand Down Expand Up @@ -463,9 +456,13 @@
"type": "array",
"uniqueItems": true
},
"inspire_field_categories": {
"inspire_categories": {
"items": {
"$ref": "elements/inspire_field.json"
"oneOf": [
{
"$ref": "elements/inspire_field.json"
}
]
},
"type": "array",
"uniqueItems": true
Expand Down
15 changes: 6 additions & 9 deletions inspire_schemas/records/institutions.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@
"title": "Department acronym",
"type": "string"
},
"external_field_categories": {
"items": {
"$ref": "elements/external_field.json"
},
"type": "array",
"uniqueItems": true
},
"extra_words": {
"items": {
"type": "string"
Expand Down Expand Up @@ -80,9 +73,13 @@
},
"type": "array"
},
"inspire_field_categories": {
"inspire_categories": {
"items": {
"$ref": "elements/inspire_field.json"
"oneOf": [
{
"$ref": "elements/inspire_field.json"
}
]
},
"type": "array",
"uniqueItems": true
Expand Down
15 changes: 6 additions & 9 deletions inspire_schemas/records/jobs.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,13 @@
"type": "array",
"uniqueItems": true
},
"external_field_categories": {
"inspire_categories": {
"items": {
"$ref": "elements/external_field.json"
},
"type": "array",
"uniqueItems": true
},
"inspire_field_categories": {
"items": {
"$ref": "elements/inspire_field.json"
"oneOf": [
{
"$ref": "elements/inspire_field.json"
}
]
},
"type": "array",
"uniqueItems": true
Expand Down
32 changes: 11 additions & 21 deletions scripts/generate_example_records.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,28 @@ jsf.format('url', function(gen, schema){ return gen.randexp('^1.*$');});
jsf.format('isbn', function(gen, schema){ return gen.randexp('^1.*$');});
jsf.format('.+, .+', function(gen, schema){ return gen.randexp('^.+, .+$');});


function extract_definition(definitions_object, defs_path) {
var keys_array = defs_path.split('/');
return definitions_object[keys_array[1]];
}


function resolve_schema(unresolved_schema, base_path, definitions) {
definitions = unresolved_schema['definitions'] || definitions;

function resolve_schema(unresolved_schema, base_path) {
var keys = [];
var resolved_schema = {};
if (Array.isArray(unresolved_schema)) {
var new_array = []
for (var value of unresolved_schema) {
if (value !== null && typeof(value) === 'object') {
new_array = new_array.concat(resolve_schema(value, base_path, definitions))
} else {
new_array = new_array.concat([value])
new_array = []
for (var value of unresolved_schema) {
if (value !== null && typeof(value) === 'object') {
new_array = new_array.concat(resolve_schema(value, base_path))
} else {
new_array = new_array.concat([value])
}
}
}
return new_array
}
for (var key in unresolved_schema) {
if (key === '$ref' && typeof(unresolved_schema[key]) === 'string' && unresolved_schema[key][0] !== '#') {
var schema_path = base_path + "/" + unresolved_schema[key];
var new_base_path = path.dirname(schema_path);
var element_schema = JSON.parse(fs.readFileSync(schema_path));
var resolved_element_schema = resolve_schema(element_schema, new_base_path, definitions);
var resolved_element_schema = resolve_schema(element_schema, new_base_path);
delete(resolved_element_schema['$schema'])
return resolved_element_schema
} else if (key === '$ref' && typeof(unresolved_schema[key ]) === 'string' && unresolved_schema[key][0] === '#') {
return resolve_schema(extract_definition(definitions, unresolved_schema[key].substring(2)), base_path, definitions);
} else {
if (resolved_schema['type'] === 'array' && !resolved_schema.hasOwnProperty('minItems')){
resolved_schema['minItems'] = 1
Expand All @@ -52,11 +41,12 @@ function resolve_schema(unresolved_schema, base_path, definitions) {
}
var value = unresolved_schema[key];
if (value !== null && typeof(value) === 'object') {
value = resolve_schema(unresolved_schema[key], base_path, definitions);
value = resolve_schema(unresolved_schema[key], base_path);
delete(value['$schema'])
}
resolved_schema[key] = value
}

}
return resolved_schema
}
Expand Down
Loading

0 comments on commit 5c05db1

Please sign in to comment.