From afbe890fd6ca7d77c50b0c7ae3543307ad6b65c6 Mon Sep 17 00:00:00 2001 From: Maximiliano Osorio Date: Sun, 22 Mar 2020 13:43:09 -0700 Subject: [PATCH] add: filter by class --- examples/dbpedia/config.yaml | 16 +- examples/modelcatalog/config.yaml | 6 +- src/main/java/edu/isi/oba/Mapper.java | 261 ++++++++++-------- src/main/java/edu/isi/oba/MapperSchema.java | 8 +- src/main/java/edu/isi/oba/Oba.java | 47 +--- src/main/java/edu/isi/oba/ObaManager.java | 6 + src/main/java/edu/isi/oba/ObaUtils.java | 43 +++ src/main/java/edu/isi/oba/Serializer.java | 18 +- .../java/edu/isi/oba/config/YamlConfig.java | 9 + src/test/config/dbpedia.yaml | 32 +++ src/test/java/edu/isi/oba/MapperTest.java | 32 +++ .../edu/isi/oba/config/YamlConfigTest.java | 21 ++ 12 files changed, 332 insertions(+), 167 deletions(-) create mode 100644 src/main/java/edu/isi/oba/ObaManager.java create mode 100644 src/test/config/dbpedia.yaml create mode 100644 src/test/java/edu/isi/oba/MapperTest.java create mode 100644 src/test/java/edu/isi/oba/config/YamlConfigTest.java diff --git a/examples/dbpedia/config.yaml b/examples/dbpedia/config.yaml index 84c5146..b48f715 100644 --- a/examples/dbpedia/config.yaml +++ b/examples/dbpedia/config.yaml @@ -1,19 +1,17 @@ ontologies: - - https://gist.githubusercontent.com/sirspock/cec147b24bd241295584dfcc21c21b93/raw/b6fa41ddf93212d967f35da20278f54d2ae2d40d/gistfile1.txt + - https://gist.githubusercontent.com/sirspock/cec147b24bd241295584dfcc21c21b93/raw/b6fa41ddf93212d967f35da20278f54d2ae2d40d/gistfile1.txt name: dbpedia openapi: openapi: 3.0.1 info: - description: This is the API of the Software Description Ontology - at [https://mintproject.github.io/Mint-ModelCatalog-Ontology/release/1.3.0/index-en.html](https://w3id.org/okn/o/sdm) - title: Model Catalog + description: This is the API of the DBpedia Ontology + title: DBpedia version: v1.3.0 externalDocs: - description: Model Catalog + description: DBpedia url: https://w3id.org/okn/o/sdm servers: - - url: https://api.models.mint.isi.edu/v1.3.0 - - url: https://dev.api.models.mint.isi.edu/v1.3.0 + - url: https:///dbpedia.dbpedia.oba.isi.edu/v1.3.0 - url: http://localhost:8080/v1.3.0 @@ -21,7 +19,9 @@ enable_get_paths: true enable_post_paths: false enable_delete_paths: false enable_put_paths: false - +classes: + - http://dbpedia.org/ontology/Genre + - http://dbpedia.org/ontology/Band firebase: key: diff --git a/examples/modelcatalog/config.yaml b/examples/modelcatalog/config.yaml index 106b069..1a73424 100644 --- a/examples/modelcatalog/config.yaml +++ b/examples/modelcatalog/config.yaml @@ -1,13 +1,13 @@ ontologies: - - https://mintproject.github.io/Mint-ModelCatalog-Ontology/release/1.3.0/ontology.xml - - https://knowledgecaptureanddiscovery.github.io/SoftwareDescriptionOntology/release/1.4.0/ontology.xml + - http://shorturl.at/fmsvM + - http://shorturl.at/nRYZ2 name: modelcatalog output_dir: outputs openapi: openapi: 3.0.1 info: - description: This is the API of the Software Description Ontology at [https://w3id.org/okn/o/sdm](https://w3id.org/okn/o/sdm) + description: This is the API of the Software Description Ontology at [https://w3id.org/okn/o/sdm](https://w3id.org/okn/o/sdm) title: Model Catalog version: v1.4.0 externalDocs: diff --git a/src/main/java/edu/isi/oba/Mapper.java b/src/main/java/edu/isi/oba/Mapper.java index 00f08de..028f7c8 100644 --- a/src/main/java/edu/isi/oba/Mapper.java +++ b/src/main/java/edu/isi/oba/Mapper.java @@ -1,6 +1,5 @@ package edu.isi.oba; -import edu.isi.oba.config.RelationConfig; import edu.isi.oba.config.YamlConfig; import io.swagger.v3.oas.models.Paths; import io.swagger.v3.oas.models.media.Schema; @@ -9,138 +8,178 @@ import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.formats.RDFXMLDocumentFormat; import org.semanticweb.owlapi.model.*; -import org.semanticweb.owlapi.rdf.rdfxml.renderer.OWLOntologyXMLNamespaceManager; + +import static edu.isi.oba.Oba.logger; import java.io.File; import java.util.*; import java.util.stream.Collectors; class Mapper { - public static final String DEFAULT_DIR_QUERY = "_default_"; - public final Map schemaNames = new HashMap<>(); - public Map schemas = new HashMap<>(); - final Paths paths = new Paths(); - List selected_paths; - List ontologies; - - public OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - - public Mapper(YamlConfig config_data) throws OWLOntologyCreationException { - List paths = config_data.getPaths(); - - this.selected_paths = paths; - List config_ontologies = config_data.getOntologies(); - String destination_dir = config_data.getOutput_dir() + File.separator + config_data.getName(); + public static final String DEFAULT_DIR_QUERY = "_default_"; + public final Map schemaNames = new HashMap<>(); + public Map schemas = new HashMap<>(); + final Paths paths = new Paths(); + List selected_paths; + List ontologies; + List selected_classes; + List mapped_classes; + YamlConfig config_data; + + public OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + + public Mapper(YamlConfig config_data) throws OWLOntologyCreationException { + this.config_data = config_data; + List paths = config_data.getPaths(); + this.selected_paths = paths; + this.mapped_classes = new ArrayList<>(); + + List config_ontologies = config_data.getOntologies(); + String destination_dir = config_data.getOutput_dir() + File.separator + config_data.getName(); + + //Load the ontology into the manager + for (String ontologyURL : config_ontologies) { + this.manager.loadOntology(IRI.create(ontologyURL)); + } + ontologies = this.manager.ontologies().collect(Collectors.toList()); - //Load the ontology into the manager - for (String ontologyURL : config_ontologies) { - this.manager.loadOntology(IRI.create(ontologyURL)); + //Create a temporal Map schemaNames with the classes + for (OWLOntology ontology : ontologies) { + Set classes = ontology.getClassesInSignature(); + setSchemaNames(classes); + } + this.selected_classes = filter_classes(); } - ontologies = this.manager.ontologies().collect(Collectors.toList()); - //Create a temporal Map schemaNames with the classes - for (OWLOntology ontology : ontologies) { - Set classes = ontology.getClassesInSignature(); - setSchemaNames(classes); - } - //Create OpenAPI spec - this.createSchemas(destination_dir, config_data); - } - - /** - * Obtain Schemas using the ontology classes - * The schemas includes the properties - * - * @param config_data - * @return schemas - */ - private void createSchemas(String destination_dir, YamlConfig config_data) { - Query query = new Query(destination_dir); - Path pathGenerator = new Path(config_data.getEnable_get_paths(), - config_data.getEnable_post_paths(), - config_data.getEnable_put_paths(), - config_data.getEnable_delete_paths() - ); - query.get_all(DEFAULT_DIR_QUERY); - - for (OWLOntology ontology : this.ontologies){ - OWLDocumentFormat format = ontology.getFormat(); - String defaultOntologyPrefixIRI = ((RDFXMLDocumentFormat) format).getDefaultPrefix(); - Set classes = ontology.getClassesInSignature(); - for (OWLClass cls : classes) { - //filter if the class prefix is not the default ontology's prefix - if (cls.getIRI() != null) { - String classPrefixIRI = cls.getIRI().getNamespace(); - if (defaultOntologyPrefixIRI.equals(classPrefixIRI)) { - //Convert from OWL Class to OpenAPI Schema. - MapperSchema mapperSchema = new MapperSchema(this.ontologies, cls, schemaNames, ontology); - //Write the query - query.write_readme(mapperSchema.name); - - //Create the schema - Schema schema = mapperSchema.getSchema(); - schemas.put(schema.getName(), schema); - - - //Add the paths - if (this.selected_paths == null){ - add_path(pathGenerator, mapperSchema); - } else { - for (String str : this.selected_paths) { - String search = str.trim().toLowerCase(); - String schemaName = mapperSchema.name.toLowerCase(); - if (search.trim().toLowerCase().equals(schemaName)) { - add_path(pathGenerator, mapperSchema); + /** + * Obtain Schemas using the ontology classes + * The schemas includes the properties + * + * @param config_data + * @return schemas + */ + public void createSchemas(String destination_dir, YamlConfig config_data) { + Query query = new Query(destination_dir); + Path pathGenerator = new Path(config_data.getEnable_get_paths(), + config_data.getEnable_post_paths(), + config_data.getEnable_put_paths(), + config_data.getEnable_delete_paths() + ); + query.get_all(DEFAULT_DIR_QUERY); + for (OWLOntology ontology : this.ontologies) { + + OWLDocumentFormat format = ontology.getFormat(); + String defaultOntologyPrefixIRI = ((RDFXMLDocumentFormat) format).getDefaultPrefix(); + Set classes = ontology.getClassesInSignature(); + + /** + * Find the classes and return the related classes + */ + for (OWLClass cls : classes) { + //filter if the class prefix is not the default ontology's prefix + if (cls.getIRI() != null) { + if (selected_classes != null && !selected_classes.contains(cls)) + continue; + add_owlclass_to_openapi(query, pathGenerator, ontology, defaultOntologyPrefixIRI, cls, true); } - } } - } - } + //User schema + Map userProperties = new HashMap<>(); + StringSchema username = new StringSchema(); + StringSchema password = new StringSchema(); + userProperties.put("username", username); + userProperties.put("password", password); + + Schema userSchema = new Schema(); + userSchema.setName("User"); + userSchema.setType("object"); + userSchema.setProperties(userProperties); + userSchema.setXml(new XML().name("User")); + schemas.put("User", userSchema); + + this.paths.addPathItem("/user/login", pathGenerator.user_login()); + } } + private List add_owlclass_to_openapi(Query query, Path pathGenerator, OWLOntology ontology, + String defaultOntologyPrefixIRI, OWLClass cls, Boolean topLevel) { + List ref = new ArrayList<>(); + String classPrefixIRI = cls.getIRI().getNamespace(); + if (defaultOntologyPrefixIRI.equals(classPrefixIRI)) { + MapperSchema mapperSchema = getMapperSchema(query, ontology, cls); + + for (OWLClass ref_class : mapperSchema.getProperties_range()) { + if (this.mapped_classes.contains(ref_class)){ + logger.info("The class " + ref_class + " exists "); + } else { + for (OWLOntology temp_ontology : this.ontologies) { + this.mapped_classes.add(ref_class); + getMapperSchema(query, temp_ontology, ref_class); + + OWLDocumentFormat format = ontology.getFormat(); + String temp_defaultOntologyPrefixIRI = ((RDFXMLDocumentFormat) format).getDefaultPrefix(); + add_owlclass_to_openapi(query, pathGenerator, temp_ontology, temp_defaultOntologyPrefixIRI, ref_class, false); + } + } + } + //Add the OpenAPI paths + if (topLevel) + addOpenAPIPaths(pathGenerator, mapperSchema, cls); + } + return ref; + } - - - //User schema - Map userProperties = new HashMap<>(); - StringSchema username = new StringSchema(); - StringSchema password = new StringSchema(); - userProperties.put("username", username); - userProperties.put("password", password); - - Schema userSchema = new Schema(); - userSchema.setName("User"); - userSchema.setType("object"); - userSchema.setProperties(userProperties); - userSchema.setXml(new XML().name("User")); - schemas.put("User", userSchema); - - this.paths.addPathItem("/user/login", pathGenerator.user_login()); + private MapperSchema getMapperSchema(Query query, OWLOntology ontology, OWLClass cls) { + //Convert from OWL Class to OpenAPI Schema. + MapperSchema mapperSchema = new MapperSchema(this.ontologies, cls, schemaNames, ontology); + //Write queries + query.write_readme(mapperSchema.name); + //Create the OpenAPI schema + Schema schema = mapperSchema.getSchema(); + schemas.put(schema.getName(), schema); + return mapperSchema; } - } + private void addOpenAPIPaths(Path pathGenerator, MapperSchema mapperSchema, OWLClass cls) { + if (selected_classes != null && !selected_classes.contains(cls)) + logger.info("Ignoring class " + cls.toString()); + else + add_path(pathGenerator, mapperSchema); + } - private void setSchemaNames(Set classes) { - for (OWLClass cls : classes) { - schemaNames.put(cls.getIRI(), cls.getIRI().getShortForm()); + private void setSchemaNames(Set classes) { + for (OWLClass cls : classes) { + schemaNames.put(cls.getIRI(), cls.getIRI().getShortForm()); + } } - } - private void add_path(Path pathGenerator, MapperSchema mapperSchema) { - String singular_name = "/" + mapperSchema.name.toLowerCase() + "s/{id}"; - String plural_name = "/" + mapperSchema.name.toLowerCase() + "s"; - //Create the plural paths: for example: /models/ - this.paths.addPathItem(plural_name, pathGenerator.generate_plural(mapperSchema.name)); - //Create the plural paths: for example: /models/id - this.paths.addPathItem(singular_name, pathGenerator.generate_singular(mapperSchema.name)); - } + private void add_path(Path pathGenerator, MapperSchema mapperSchema) { + String singular_name = "/" + mapperSchema.name.toLowerCase() + "s/{id}"; + String plural_name = "/" + mapperSchema.name.toLowerCase() + "s"; + //Create the plural paths: for example: /models/ + this.paths.addPathItem(plural_name, pathGenerator.generate_plural(mapperSchema.name)); + //Create the plural paths: for example: /models/id + this.paths.addPathItem(singular_name, pathGenerator.generate_singular(mapperSchema.name)); + } - private void add_path_relation(Path pathGenerator, String schema_name, String predicate, String path) { - String relation = "/" + schema_name.toLowerCase() + "s/{id}/" + path; - this.paths.addPathItem(relation, pathGenerator.generate_plural(schema_name)); + private void add_path_relation(Path pathGenerator, String schema_name, String predicate, String path) { + String relation = "/" + schema_name.toLowerCase() + "s/{id}/" + path; + this.paths.addPathItem(relation, pathGenerator.generate_plural(schema_name)); - } + } + public List filter_classes() { + List selected_classes_iri = this.config_data.getClasses(); + List filtered_classes = new ArrayList(); + for (OWLOntology ontology : this.ontologies) { + for (OWLClass cls : ontology.getClassesInSignature()) { + if (selected_classes_iri.contains(cls.getIRI().toString())) { + filtered_classes.add(cls); + } + } + } + return filtered_classes; + } } diff --git a/src/main/java/edu/isi/oba/MapperSchema.java b/src/main/java/edu/isi/oba/MapperSchema.java index bbc28d5..781c6a4 100644 --- a/src/main/java/edu/isi/oba/MapperSchema.java +++ b/src/main/java/edu/isi/oba/MapperSchema.java @@ -28,7 +28,11 @@ class MapperSchema { private final Schema schema; private OWLOntology ontology_cls; private OWLReasonerFactory reasonerFactory; + public List properties_range; + public List getProperties_range() { + return properties_range; + } public Schema getSchema() { return schema; @@ -43,6 +47,8 @@ public MapperSchema(List ontologies, OWLClass cls, Map reasonerFactory = new StructuralReasonerFactory(); this.reasoner = reasonerFactory.createReasoner(this.ontology_cls); + properties_range = new ArrayList<>(); + this.name = getSchemaName(cls); this.properties = setProperties(); this.schema = setSchema(); @@ -237,7 +243,6 @@ private List getCodeGenTypesByRangeData(Set r private List getCodeGenTypesByRangeObject(Set ranges, OWLObjectProperty odp, OWLClass owlThing) { List objectProperty = new ArrayList<>(); - for (OWLObjectPropertyAxiom propertyRangeAxiom : ranges) { for (OWLEntity rangeClass : propertyRangeAxiom.getSignature()) { if (!rangeClass.containsEntityInSignature(odp)) { @@ -245,6 +250,7 @@ private List getCodeGenTypesByRangeObject(Set custom_paths = config_data.getCustom_paths(); OpenAPI openapi_base = config_data.getOpenapi(); String custom_queries_dir = config_data.getCustom_queries_directory(); @@ -108,41 +106,4 @@ private static void generate_openapi_spec(OpenAPI openapi_base, } - private static YamlConfig get_yaml_data(String config_yaml) { - Constructor constructor = new Constructor(YamlConfig.class); - Yaml yaml = new Yaml(constructor); - - InputStream config_input = null; - try { - config_input = new FileInputStream(new File(config_yaml)); - } catch (FileNotFoundException e) { - System.err.println("Configuration file not found: " + config_yaml); - System.exit(1); - } - //Yaml config parse - return yaml.loadAs(config_input, YamlConfig.class); - } - - private static String get_config_yaml(String[] args) { - //obtain the options to pass configuration - Options options = new Options(); - Option input = new Option("c", "config", true, "configuration file path"); - input.setRequired(true); - options.addOption(input); - - CommandLineParser parser = new DefaultParser(); - HelpFormatter formatter = new HelpFormatter(); - CommandLine cmd; - String config_yaml = null; - - try { - cmd = parser.parse(options, args); - config_yaml = cmd.getOptionValue("config"); - } catch (ParseException e) { - System.out.println(e.getMessage()); - formatter.printHelp("utiConfiguration filelity-name", options); - System.exit(1); - } - return config_yaml; - } } diff --git a/src/main/java/edu/isi/oba/ObaManager.java b/src/main/java/edu/isi/oba/ObaManager.java new file mode 100644 index 0000000..a3e67a5 --- /dev/null +++ b/src/main/java/edu/isi/oba/ObaManager.java @@ -0,0 +1,6 @@ +package edu.isi.oba; + +public class ObaManager { + public void filter() { + } +} diff --git a/src/main/java/edu/isi/oba/ObaUtils.java b/src/main/java/edu/isi/oba/ObaUtils.java index 4f77231..f033d3d 100644 --- a/src/main/java/edu/isi/oba/ObaUtils.java +++ b/src/main/java/edu/isi/oba/ObaUtils.java @@ -1,5 +1,10 @@ package edu.isi.oba; +import edu.isi.oba.config.YamlConfig; +import org.apache.commons.cli.*; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.Constructor; + import java.io.*; import java.nio.file.Files; import java.nio.file.StandardCopyOption; @@ -125,4 +130,42 @@ public static void copyFolder(File sourceFolder, File destinationFolder) throws System.out.println("File copied :: " + destinationFolder); } } + + public static String get_config_yaml(String[] args) { + //obtain the options to pass configuration + Options options = new Options(); + Option input = new Option("c", "config", true, "configuration file path"); + input.setRequired(true); + options.addOption(input); + + CommandLineParser parser = new DefaultParser(); + HelpFormatter formatter = new HelpFormatter(); + CommandLine cmd; + String config_yaml = null; + + try { + cmd = parser.parse(options, args); + config_yaml = cmd.getOptionValue("config"); + } catch (ParseException e) { + System.out.println(e.getMessage()); + formatter.printHelp("utiConfiguration filelity-name", options); + System.exit(1); + } + return config_yaml; + } + + public static YamlConfig get_yaml_data(String config_yaml) { + Constructor constructor = new Constructor(YamlConfig.class); + Yaml yaml = new Yaml(constructor); + + InputStream config_input = null; + try { + config_input = new FileInputStream(new File(config_yaml)); + } catch (FileNotFoundException e) { + System.err.println("Configuration file not found: " + config_yaml); + System.exit(1); + } + //Yaml config parse + return yaml.loadAs(config_input, YamlConfig.class); + } } \ No newline at end of file diff --git a/src/main/java/edu/isi/oba/Serializer.java b/src/main/java/edu/isi/oba/Serializer.java index 7aa9cca..60e6dfd 100644 --- a/src/main/java/edu/isi/oba/Serializer.java +++ b/src/main/java/edu/isi/oba/Serializer.java @@ -1,11 +1,14 @@ package edu.isi.oba; +import io.swagger.parser.OpenAPIParser; import io.swagger.v3.oas.models.*; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.servers.Server; +import io.swagger.v3.parser.core.models.ParseOptions; +import io.swagger.v3.parser.core.models.SwaggerParseResult; import org.openapitools.codegen.serializer.SerializerUtils; import org.semanticweb.owlapi.model.IRI; @@ -18,6 +21,7 @@ class Serializer { //TODO: validate the yaml + String openapi_path; public Serializer(Mapper mapper, java.nio.file.Path dir, OpenAPI openAPI, LinkedHashMap custom_paths) throws IOException { Map extensions = new HashMap(); final String openapi_file = "openapi.yaml"; @@ -49,10 +53,22 @@ public Serializer(Mapper mapper, java.nio.file.Path dir, OpenAPI openAPI, Linke //write the filename String content = SerializerUtils.toYamlString(openAPI); - File file = new File(dir + File.separator + openapi_file ); + this.openapi_path = dir + File.separator + openapi_file; + File file = new File(openapi_path); BufferedWriter writer = new BufferedWriter(new FileWriter(file.getAbsoluteFile())); writer.write(content); writer.close(); + this.validate(); + } + + private void validate(){ + ParseOptions options = new ParseOptions(); + options.setResolve(true); + SwaggerParseResult result = new OpenAPIParser().readLocation(openapi_path, null, options); + List messageList = result.getMessages(); + Set errors = new HashSet<>(messageList); + Set warnings = new HashSet<>(); + } private SecurityScheme getSecurityScheme(Map extensions) { diff --git a/src/main/java/edu/isi/oba/config/YamlConfig.java b/src/main/java/edu/isi/oba/config/YamlConfig.java index 1d7dc50..c5edd7f 100644 --- a/src/main/java/edu/isi/oba/config/YamlConfig.java +++ b/src/main/java/edu/isi/oba/config/YamlConfig.java @@ -24,6 +24,7 @@ public class YamlConfig { public FirebaseConfig firebase; public Map> relations; private LinkedHashMap custom_paths = null; + public List classes; public Boolean getEnable_get_paths() { @@ -140,5 +141,13 @@ public OpenAPI getOpenapi() { public void setOpenapi(OpenAPI openapi) { this.openapi = openapi; } + + public List getClasses() { + return this.classes; + } + + public void setClasses(List classes) { + this.classes = classes; + } } diff --git a/src/test/config/dbpedia.yaml b/src/test/config/dbpedia.yaml new file mode 100644 index 0000000..b48f715 --- /dev/null +++ b/src/test/config/dbpedia.yaml @@ -0,0 +1,32 @@ +ontologies: + - https://gist.githubusercontent.com/sirspock/cec147b24bd241295584dfcc21c21b93/raw/b6fa41ddf93212d967f35da20278f54d2ae2d40d/gistfile1.txt +name: dbpedia +openapi: + openapi: 3.0.1 + info: + description: This is the API of the DBpedia Ontology + title: DBpedia + version: v1.3.0 + externalDocs: + description: DBpedia + url: https://w3id.org/okn/o/sdm + servers: + - url: https:///dbpedia.dbpedia.oba.isi.edu/v1.3.0 + - url: http://localhost:8080/v1.3.0 + + +enable_get_paths: true +enable_post_paths: false +enable_delete_paths: false +enable_put_paths: false +classes: + - http://dbpedia.org/ontology/Genre + - http://dbpedia.org/ontology/Band +firebase: + key: + +endpoint: + url: http://endpoint.mint.isi.edu/modelCatalog-1.2.0 + prefix: https://w3id.org/okn/i/mint + graph_base: http://ontosoft.isi.edu:3030/modelCatalog-1.2.0/data/ + diff --git a/src/test/java/edu/isi/oba/MapperTest.java b/src/test/java/edu/isi/oba/MapperTest.java new file mode 100644 index 0000000..dc0a614 --- /dev/null +++ b/src/test/java/edu/isi/oba/MapperTest.java @@ -0,0 +1,32 @@ +package edu.isi.oba; + +import edu.isi.oba.config.YamlConfig; +import org.junit.Assert; +import org.junit.Test; +import org.semanticweb.owlapi.model.OWLClass; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static edu.isi.oba.ObaUtils.get_yaml_data; + +public class MapperTest { + @Test + public void testFilter() throws Exception{ + String example_dbpedia = "src/test/config/dbpedia.yaml"; + String config_test_file_path = example_dbpedia; + YamlConfig config_data = get_yaml_data(config_test_file_path); + Mapper mapper = new Mapper(config_data); + List config = config_data.getClasses(); + List classes = mapper.filter_classes(); + List filter_classes = new ArrayList(); + for (OWLClass _class : classes){ + filter_classes.add(_class.getIRI().getIRIString()); + } + Collections.sort(filter_classes); + Collections.sort(config); + Assert.assertEquals(config, filter_classes); + + } +} diff --git a/src/test/java/edu/isi/oba/config/YamlConfigTest.java b/src/test/java/edu/isi/oba/config/YamlConfigTest.java new file mode 100644 index 0000000..01cfd93 --- /dev/null +++ b/src/test/java/edu/isi/oba/config/YamlConfigTest.java @@ -0,0 +1,21 @@ +package edu.isi.oba.config; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static edu.isi.oba.ObaUtils.get_yaml_data; +import static org.junit.Assert.assertThat; + +public class YamlConfigTest { + @Test + public void getSelectedClasses(){ + String config_test_file_path = "examples/dbpedia/config.yaml"; + YamlConfig config_data = get_yaml_data(config_test_file_path); + List expected = Arrays.asList("http://dbpedia.org/ontology/Genre", "http://dbpedia.org/ontology/Author"); + List config = config_data.getClasses(); + Assert.assertEquals(expected, config); + } +}