8000 Fix add-prefixes and add test by beckyjackson · Pull Request #715 · ontodev/robot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix add-prefixes and add test #715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
< 8000 span class="sr-only">Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Reduced time spent loading datasets for [`query`] in [#666]
- Fix writing JSON format to use `OutputStream` with ['convert'] in [#671]
- Fix IRI resolution for `template` in [#689]
- Fix issue with `--add-prefixes` option in [#715]


## [1.6.0] - 2020-03-04
Expand Down Expand Up @@ -187,6 +188,7 @@ First official release of ROBOT!
[`report`]: http://robot.obolibrary.org/report
[`template`]: http://robot.obolibrary.org/template

[#715]: https://github.com/ontodev/robot/pull/715
[#689]: https://github.c 10000 om/ontodev/robot/pull/689
[#685]: https://github.com/ontodev/robot/pull/685
[#671]: https://github.com/ontodev/robot/pull/671
Expand Down
12 changes: 12 additions & 0 deletions robot-core/src/main/java/org/obolibrary/robot/IOHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,19 @@ public void addPrefixes(String prefixPath) throws IOException {
throw new IOException(String.format(fileDoesNotExistError, prefixPath));
}
Context context1 = parseContext(FileUtils.readFileToString(prefixFile));
addPrefixes(context1);
}

/**
* Given a Context, add the prefix mappings to the current JSON-LD context.
*
* @param context1 Context to add
* @throws IOException if the Context cannot be set
*/
public void addPrefixes(Context context1) throws IOException {
context.putAll(context1.getPrefixes(false));
context.remove("@base");
setContext((Map<String, Object>) context);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions robot-core/src/test/java/org/obolibrary/robot/IOHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@

/** Tests for IOHelper. */
public class IOHelperTest extends CoreTest {

/**
* Test adding prefixes using the addPrefixes method
*
* @throws IOException on problem creating IOHelper or adding prefixes
*/
@Test
public void testAddPrefixes() throws IOException {
// IOHelper without default prefixes
IOHelper ioh = new IOHelper(false);

// Single prefix to add from a context
String inputContext = "{\n \"@context\" : {\n \"foo\" : \"http://foo.bar\"\n }\n}";
Context context = IOHelper.parseContext(inputContext);
ioh.addPrefixes(context);

// Get the context back from IOHelper
String outputContext = ioh.getContextString();
assertEquals(inputContext, outputContext);
}

/**
* Test loading JSON files.
*
Expand Down
0