Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ boolean isCondensationEnabled() {
return pr.hasMatchedOption("condensation") ? enableCondensation : defaultEnableCondensation;
}

@Option(names = "--condense-all-slots",
defaultValue = "false",
description = "Condense all slots that can be condensed, even those for which the specification recommends against condensation. Note that `--no-condensation` takes precedence.")
boolean condenseAll;

@Option(names = { "-f", "--output-format" },
paramLabel = "FMT",
description = "Write output in the specified format. Allowed values: ${COMPLETION-CANDIDATES}. Default is tsv.",
Expand Down Expand Up @@ -824,6 +829,7 @@ private SSSOMWriter getWriter(String filename, String metaFilename, Serialisatio

writer.setExtraMetadataPolicy(outputOpts.getExtraMetadataPolicy());
writer.setCondensationEnabled(outputOpts.isCondensationEnabled());
writer.setForceCondensation(outputOpts.condenseAll);
writer.setSortingEnabled(outputOpts.sortMappings);
writer.setTargetVersion(outputOpts.forceVersion);
return writer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.incenp.obofoundry.sssom.slots.ExtensionSlot;
import org.incenp.obofoundry.sssom.slots.Slot;
import org.incenp.obofoundry.sssom.slots.SlotHelper;
import org.incenp.obofoundry.sssom.slots.SlotPropagator;
import org.incenp.obofoundry.sssom.slots.SlotVisitorBase;
import org.incenp.obofoundry.sssom.slots.StringSlot;
import org.incenp.obofoundry.sssom.slots.VersionSlot;
Expand Down Expand Up @@ -132,7 +131,7 @@ public void setWriteCurieMapInContext(boolean enabled) {
@Override
protected void doWrite(MappingSet mappingSet) throws IOException {
// Condense the set
Set<String> condensedSlots = new SlotPropagator(condensationPolicy).condense(mappingSet, true);
Set<String> condensedSlots = condenseSet(mappingSet);

// Determine minimum compliant version
mappingSet.setSssomVersion(Version.getCompliantVersion(mappingSet));
Expand Down
24 changes: 23 additions & 1 deletion core/src/main/java/org/incenp/obofoundry/sssom/SSSOMWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public abstract class SSSOMWriter {
protected Version targetVersion = Version.LATEST;
protected ExtensionSlotManager extensionManager;
protected PrefixManager prefixManager = new PrefixManager();
protected boolean forceCondensation = false;
private boolean customMap = false;
private boolean sortMappings = true;

Expand Down Expand Up @@ -85,6 +86,27 @@ public void setCondensationEnabled(boolean enabled) {
condensationPolicy = enabled ? PropagationPolicy.NeverReplace : PropagationPolicy.Disabled;
}

/**
* Enables or disables the condensation of “propagatable slots” that the SSSOM
* specification recommends <em>not</em> to condense.
* <p>
* The general rule about condensation is that all propagatable slots are
* condensable and should be condensed, but some slots are an exception in that,
* while they may be condensed, they generally should not be. The default
* behaviour of SSSOM writers is therefore not to condense such slots. Use this
* method to change that behaviour.
* <p>
* Note that {@link #setCondensationEnabled(boolean)} takes precedence over this
* method. That is, if condensation is disabled, then calling
* <code>setForceCondensation(true)</code> has no effect.
*
* @param enabled If <code>true</code>, forces the writer to condense slots that
* are better left non-condensed.
*/
public void setForceCondensation(boolean enabled) {
forceCondensation = enabled;
}

/**
* Sets the highest version of the SSSOM specification that the written set must
* be compliant with.
Expand Down Expand Up @@ -202,7 +224,7 @@ protected Set<String> getUsedPrefixes(MappingSet mappingSet, boolean includeBuil
* (may be empty if no slots have been condensed at all).
*/
protected Set<String> condenseSet(MappingSet mappingSet) {
return new SlotPropagator(condensationPolicy, targetVersion).condense(mappingSet, true);
return new SlotPropagator(condensationPolicy, targetVersion, forceCondensation).condense(mappingSet, true);
}

/*
Expand Down
114 changes: 114 additions & 0 deletions core/src/main/java/org/incenp/obofoundry/sssom/model/MappingSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ public class MappingSet {
@Propagatable
private String objectSourceVersion;

@JsonProperty("predicate_id")
@EntityReference
@Propagatable(condensationDiscouraged=true)
@SlotURI("http://www.w3.org/2002/07/owl#annotatedProperty")
@Versionable(addedIn = Version.SSSOM_1_1)
private String predicateId;

@JsonProperty("predicate_label")
@Propagatable
@Versionable(addedIn = Version.SSSOM_1_1)
private String predicateLabel;

@JsonProperty("predicate_type")
@Propagatable
@Versionable(addedIn = Version.SSSOM_1_1)
Expand Down Expand Up @@ -138,6 +150,12 @@ public class MappingSet {
@SlotURI("http://purl.org/dc/terms/created")
private LocalDate mappingDate;

@JsonProperty("mapping_justification")
@EntityReference
@Propagatable(condensationDiscouraged=true)
@Versionable(addedIn = Version.SSSOM_1_1)
private String mappingJustification;

@JsonProperty("publication_date")
@SlotURI("http://purl.org/dc/terms/issued")
private LocalDate publicationDate;
Expand Down Expand Up @@ -224,13 +242,16 @@ protected MappingSet(final Version sssomVersion,
final EntityType objectType,
final String objectSource,
final String objectSourceVersion,
final String predicateId,
final String predicateLabel,
final EntityType predicateType,
final String mappingProvider,
final List<String> cardinalityScope,
final String mappingTool,
final String mappingToolId,
final String mappingToolVersion,
final LocalDate mappingDate,
final String mappingJustification,
final LocalDate publicationDate,
final List<String> subjectMatchField,
final List<String> objectMatchField,
Expand Down Expand Up @@ -263,13 +284,16 @@ protected MappingSet(final Version sssomVersion,
this.objectType = objectType;
this.objectSource = objectSource;
this.objectSourceVersion = objectSourceVersion;
this.predicateId = predicateId;
this.predicateLabel = predicateLabel;
this.predicateType = predicateType;
this.mappingProvider = mappingProvider;
this.cardinalityScope = cardinalityScope;
this.mappingTool = mappingTool;
this.mappingToolId = mappingToolId;
this.mappingToolVersion = mappingToolVersion;
this.mappingDate = mappingDate;
this.mappingJustification = mappingJustification;
this.publicationDate = publicationDate;
this.subjectMatchField = subjectMatchField;
this.objectMatchField = objectMatchField;
Expand Down Expand Up @@ -618,6 +642,34 @@ public void setObjectSourceVersion(final String value) {
this.objectSourceVersion = value;
}

/**
* Gets the value of the <code>predicate_id</code> slot.
*/
public String getPredicateId() {
return this.predicateId;
}

/**
* Sets the value of the <code>predicate_id</code> slot.
*/
public void setPredicateId(final String value) {
this.predicateId = value;
}

/**
* Gets the value of the <code>predicate_label</code> slot.
*/
public String getPredicateLabel() {
return this.predicateLabel;
}

/**
* Sets the value of the <code>predicate_label</code> slot.
*/
public void setPredicateLabel(final String value) {
this.predicateLabel = value;
}

/**
* Gets the value of the <code>predicate_type</code> slot.
*/
Expand Down Expand Up @@ -731,6 +783,20 @@ public void setMappingDate(final LocalDate value) {
this.mappingDate = value;
}

/**
* Gets the value of the <code>mapping_justification</code> slot.
*/
public String getMappingJustification() {
return this.mappingJustification;
}

/**
* Sets the value of the <code>mapping_justification</code> slot.
*/
public void setMappingJustification(final String value) {
this.mappingJustification = value;
}

/**
* Gets the value of the <code>publication_date</code> slot.
*/
Expand Down Expand Up @@ -1156,6 +1222,16 @@ public String toString() {
sb.append(this.objectSourceVersion);
sb.append(",");
}
if ( this.predicateId != null ) {
sb.append("predicate_id=");
sb.append(this.predicateId);
sb.append(",");
}
if ( this.predicateLabel != null ) {
sb.append("predicate_label=");
sb.append(this.predicateLabel);
sb.append(",");
}
if ( this.predicateType != null ) {
sb.append("predicate_type=");
sb.append(this.predicateType);
Expand Down Expand Up @@ -1191,6 +1267,11 @@ public String toString() {
sb.append(this.mappingDate);
sb.append(",");
}
if ( this.mappingJustification != null ) {
sb.append("mapping_justification=");
sb.append(this.mappingJustification);
sb.append(",");
}
if ( this.publicationDate != null ) {
sb.append("publication_date=");
sb.append(this.publicationDate);
Expand Down Expand Up @@ -1294,13 +1375,16 @@ public boolean equals(final Object o) {
if ( this.objectType == null ? other.objectType != null : !this.objectType.equals(other.objectType)) return false;
if ( this.objectSource == null ? other.objectSource != null : !this.objectSource.equals(other.objectSource)) return false;
if ( this.objectSourceVersion == null ? other.objectSourceVersion != null : !this.objectSourceVersion.equals(other.objectSourceVersion)) return false;
if ( this.predicateId == null ? other.predicateId != null : !this.predicateId.equals(other.predicateId)) return false;
if ( this.predicateLabel == null ? other.predicateLabel != null : !this.predicateLabel.equals(other.predicateLabel)) return false;
if ( this.predicateType == null ? other.predicateType != null : !this.predicateType.equals(other.predicateType)) return false;
if ( this.mappingProvider == null ? other.mappingProvider != null : !this.mappingProvider.equals(other.mappingProvider)) return false;
if ( this.cardinalityScope == null ? other.cardinalityScope != null : !this.cardinalityScope.equals(other.cardinalityScope)) return false;
if ( this.mappingTool == null ? other.mappingTool != null : !this.mappingTool.equals(other.mappingTool)) return false;
if ( this.mappingToolId == null ? other.mappingToolId != null : !this.mappingToolId.equals(other.mappingToolId)) return false;
if ( this.mappingToolVersion == null ? other.mappingToolVersion != null : !this.mappingToolVersion.equals(other.mappingToolVersion)) return false;
if ( this.mappingDate == null ? other.mappingDate != null : !this.mappingDate.equals(other.mappingDate)) return false;
if ( this.mappingJustification == null ? other.mappingJustification != null : !this.mappingJustification.equals(other.mappingJustification)) return false;
if ( this.publicationDate == null ? other.publicationDate != null : !this.publicationDate.equals(other.publicationDate)) return false;
if ( this.subjectMatchField == null ? other.subjectMatchField != null : !this.subjectMatchField.equals(other.subjectMatchField)) return false;
if ( this.objectMatchField == null ? other.objectMatchField != null : !this.objectMatchField.equals(other.objectMatchField)) return false;
Expand Down Expand Up @@ -1344,13 +1428,16 @@ public int hashCode() {
result = result * PRIME + (this.objectType == null ? 43 : this.objectType.hashCode());
result = result * PRIME + (this.objectSource == null ? 43 : this.objectSource.hashCode());
result = result * PRIME + (this.objectSourceVersion == null ? 43 : this.objectSourceVersion.hashCode());
result = result * PRIME + (this.predicateId == null ? 43 : this.predicateId.hashCode());
result = result * PRIME + (this.predicateLabel == null ? 43 : this.predicateLabel.hashCode());
result = result * PRIME + (this.predicateType == null ? 43 : this.predicateType.hashCode());
result = result * PRIME + (this.mappingProvider == null ? 43 : this.mappingProvider.hashCode());
result = result * PRIME + (this.cardinalityScope == null ? 43 : this.cardinalityScope.hashCode());
result = result * PRIME + (this.mappingTool == null ? 43 : this.mappingTool.hashCode());
result = result * PRIME + (this.mappingToolId == null ? 43 : this.mappingToolId.hashCode());
result = result * PRIME + (this.mappingToolVersion == null ? 43 : this.mappingToolVersion.hashCode());
result = result * PRIME + (this.mappingDate == null ? 43 : this.mappingDate.hashCode());
result = result * PRIME + (this.mappingJustification == null ? 43 : this.mappingJustification.hashCode());
result = result * PRIME + (this.publicationDate == null ? 43 : this.publicationDate.hashCode());
result = result * PRIME + (this.subjectMatchField == null ? 43 : this.subjectMatchField.hashCode());
result = result * PRIME + (this.objectMatchField == null ? 43 : this.objectMatchField.hashCode());
Expand Down Expand Up @@ -1387,13 +1474,16 @@ public static class MappingSetBuilder {
private EntityType objectType;
private String objectSource;
private String objectSourceVersion;
private String predicateId;
private String predicateLabel;
private EntityType predicateType;
private String mappingProvider;
private List<String> cardinalityScope;
private String mappingTool;
private String mappingToolId;
private String mappingToolVersion;
private LocalDate mappingDate;
private String mappingJustification;
private LocalDate publicationDate;
private List<String> subjectMatchField;
private List<String> objectMatchField;
Expand Down Expand Up @@ -1502,6 +1592,16 @@ public MappingSet.MappingSetBuilder objectSourceVersion(final String objectSourc
return this;
}

public MappingSet.MappingSetBuilder predicateId(final String predicateId) {
this.predicateId = predicateId;
return this;
}

public MappingSet.MappingSetBuilder predicateLabel(final String predicateLabel) {
this.predicateLabel = predicateLabel;
return this;
}

public MappingSet.MappingSetBuilder predicateType(final EntityType predicateType) {
this.predicateType = predicateType;
return this;
Expand Down Expand Up @@ -1537,6 +1637,11 @@ public MappingSet.MappingSetBuilder mappingDate(final LocalDate mappingDate) {
return this;
}

public MappingSet.MappingSetBuilder mappingJustification(final String mappingJustification) {
this.mappingJustification = mappingJustification;
return this;
}

public MappingSet.MappingSetBuilder publicationDate(final LocalDate publicationDate) {
this.publicationDate = publicationDate;
return this;
Expand Down Expand Up @@ -1626,13 +1731,16 @@ public MappingSet build() {
this.objectType,
this.objectSource,
this.objectSourceVersion,
this.predicateId,
this.predicateLabel,
this.predicateType,
this.mappingProvider,
this.cardinalityScope,
this.mappingTool,
this.mappingToolId,
this.mappingToolVersion,
this.mappingDate,
this.mappingJustification,
this.publicationDate,
this.subjectMatchField,
this.objectMatchField,
Expand Down Expand Up @@ -1668,13 +1776,16 @@ public String toString() {
+ ", objectType=" + this.objectType
+ ", objectSource=" + this.objectSource
+ ", objectSourceVersion=" + this.objectSourceVersion
+ ", predicateId=" + this.predicateId
+ ", predicateLabel=" + this.predicateLabel
+ ", predicateType=" + this.predicateType
+ ", mappingProvider=" + this.mappingProvider
+ ", cardinalityScope=" + this.cardinalityScope
+ ", mappingTool=" + this.mappingTool
+ ", mappingToolId=" + this.mappingToolId
+ ", mappingToolVersion=" + this.mappingToolVersion
+ ", mappingDate=" + this.mappingDate
+ ", mappingJustification=" + this.mappingJustification
+ ", publicationDate=" + this.publicationDate
+ ", subjectMatchField=" + this.subjectMatchField
+ ", objectMatchField=" + this.objectMatchField
Expand Down Expand Up @@ -1716,13 +1827,16 @@ public MappingSet.MappingSetBuilder toBuilder() {
.objectType(this.objectType)
.objectSource(this.objectSource)
.objectSourceVersion(this.objectSourceVersion)
.predicateId(this.predicateId)
.predicateLabel(this.predicateLabel)
.predicateType(this.predicateType)
.mappingProvider(this.mappingProvider)
.cardinalityScope(this.cardinalityScope)
.mappingTool(this.mappingTool)
.mappingToolId(this.mappingToolId)
.mappingToolVersion(this.mappingToolVersion)
.mappingDate(this.mappingDate)
.mappingJustification(this.mappingJustification)
.publicationDate(this.publicationDate)
.subjectMatchField(this.subjectMatchField)
.objectMatchField(this.objectMatchField)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
@Retention(RUNTIME)
@Target(FIELD)
public @interface Propagatable {

boolean condensationDiscouraged() default false;
}
12 changes: 12 additions & 0 deletions core/src/main/java/org/incenp/obofoundry/sssom/slots/Slot.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ public boolean isPropagatable(Version inVersion) {
return field.isAnnotationPresent(Propagatable.class) && getCompliantVersion().isCompatibleWith(inVersion);
}

/**
* Indicates whether the SSSOM specification recommends against condensing this
* slot.
*
* @return {@code true} if condensing the slot is discouraged by the
* specification, otherwise {@code false}.
*/
public boolean isCondensationDiscouraged() {
Propagatable annot = field.getAnnotation(Propagatable.class);
return annot != null ? annot.condensationDiscouraged() : false;
}

/**
* Indicates whether the slot is expected to contain a URI.
*
Expand Down
Loading
Loading