Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/fill-modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ Like derive in that it records `prov:wasDerivedFrom`, but — like supersede —
The intent is "publish a variant that claims the same identity/root, but as a
distinct, independently-authored nanopub" (e.g. a competing definition of the
same resource by a different author). Menu action: `OverrideAction` ("edit as
overriding nanopublication").
overriding nanopublication"), offered only for a nanopub that introduces or describes
a resource other than one it embeds
([#920](https://github.com/knowledgepixels/nanodash/issues/920)): for any other,
there is nothing for an override to keep, and it would make the same nanopub as
deriving.

> Note: an override nanopub is currently **indistinguishable from a derived one
> at the RDF level** — it reuses the same `prov:wasDerivedFrom` pubinfo template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.knowledgepixels.nanodash.template.TemplateData;
import org.nanopub.Nanopub;
import org.nanopub.NanopubUtils;

import java.util.Set;

/**
* Represents an action that creates a new nanopublication overriding an existing one:
Expand Down Expand Up @@ -55,11 +58,21 @@ public boolean isApplicableToOthersNanopubs() {
}

/**
* {@inheritDoc}
* Applicable only to a nanopublication that introduces or describes a resource, other than
* one it embeds: that is what an override keeps and deriving would not (see
* docs/fill-modes.md). A nanopublication with a root definition introduces the resource it
* defines, so that is covered too. Overriding anything else would make the same
* nanopublication as deriving does (issue #920).
*
* @param np the nanopublication to check
* @return true if the nanopublication has an identity an override would keep
*/
@Override
public boolean isApplicableTo(Nanopub np) {
return true;
// Embedded resources are minted afresh by an override too, as by deriving.
Set<String> keptIriIds = NanopubUtils.getIntroducedIriIds(np);
keptIriIds.removeAll(NanopubUtils.getEmbeddedIriIds(np));
return !keptIriIds.isEmpty();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.knowledgepixels.nanodash.action;

import com.knowledgepixels.nanodash.utils.TestUtils;
import org.eclipse.rdf4j.model.IRI;
import org.junit.jupiter.api.Test;
import org.nanopub.MalformedNanopubException;
import org.nanopub.Nanopub;
import org.nanopub.NanopubAlreadyFinalizedException;
import org.nanopub.NanopubCreator;
import org.nanopub.vocabulary.NPX;

import static com.knowledgepixels.nanodash.action.NanopubAction.getEncodedUri;
import static com.knowledgepixels.nanodash.utils.TestUtils.anyIri;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class OverrideActionTest {

private static final String NP_URI = TestUtils.NANOPUB_URI;

/**
* A nanopublication whose pubinfo states, of the nanopublication itself, each given
* predicate with the resource of the local name after it, in the nanopublication's own
* namespace.
*/
private static Nanopub nanopub(Object... predicatesAndLocalNames) throws MalformedNanopubException, NanopubAlreadyFinalizedException {
NanopubCreator creator = TestUtils.getNanopubCreator(NP_URI);
creator.addAssertionStatement(TestUtils.vf.createStatement(anyIri, anyIri, anyIri));
creator.addProvenanceStatement(creator.getAssertionUri(), anyIri, anyIri);
creator.addPubinfoStatement(creator.getNanopubUri(), anyIri, anyIri);
for (int i = 0; i < predicatesAndLocalNames.length; i += 2) {
creator.addPubinfoStatement(creator.getNanopubUri(), (IRI) predicatesAndLocalNames[i],
TestUtils.vf.createIRI(NP_URI + "/" + predicatesAndLocalNames[i + 1]));
}
return creator.finalizeNanopub();
}

@Test
void getLinkLabel() throws MalformedNanopubException, NanopubAlreadyFinalizedException {
assertEquals("edit as overriding nanopublication", new OverrideAction().getLinkLabel(TestUtils.createNanopub()));
}

@Test
void getParamString() throws MalformedNanopubException, NanopubAlreadyFinalizedException {
Nanopub nanopub = TestUtils.createNanopub();
assertEquals("override=" + getEncodedUri(nanopub), new OverrideAction().getParamString(nanopub));
}

@Test
void isApplicableToOwnAndOthersNanopubs() {
assertTrue(new OverrideAction().isApplicableToOwnNanopubs());
assertTrue(new OverrideAction().isApplicableToOthersNanopubs());
}

@Test
void applicableToANanopubThatIntroducesSomething() throws MalformedNanopubException, NanopubAlreadyFinalizedException {
// E.g. a space definition, a view, or a statement.
assertTrue(new OverrideAction().isApplicableTo(nanopub(NPX.INTRODUCES, "statement")));
}

@Test
void applicableToANanopubThatDescribesSomething() throws MalformedNanopubException, NanopubAlreadyFinalizedException {
assertTrue(new OverrideAction().isApplicableTo(nanopub(NPX.DESCRIBES, "thing")));
}

@Test
void notApplicableToANanopubThatIntroducesNothing() throws MalformedNanopubException, NanopubAlreadyFinalizedException {
// E.g. a role assignment: overriding it would make the same nanopublication as deriving.
assertFalse(new OverrideAction().isApplicableTo(TestUtils.createNanopub()));
}

@Test
void notApplicableToANanopubThatOnlyEmbedsSomething() throws MalformedNanopubException, NanopubAlreadyFinalizedException {
// E.g. a view display: an override mints its embedded display afresh, as deriving does.
assertFalse(new OverrideAction().isApplicableTo(nanopub(NPX.EMBEDS, "display")));
}

@Test
void applicableToANanopubThatEmbedsOneThingAndIntroducesAnother() throws MalformedNanopubException, NanopubAlreadyFinalizedException {
// E.g. a template: it embeds the template and introduces its kind, which an override keeps.
assertTrue(new OverrideAction().isApplicableTo(nanopub(NPX.EMBEDS, "template", NPX.INTRODUCES, "templateKind")));
}

}