use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.
the class AbstractDefaultFunctionService method getPropertyFunctions.
@Override
public Collection<? extends PropertyFunctionDefinition> getPropertyFunctions(String categoryId) {
Collection<? extends PropertyFunctionDefinition> functions = super.getPropertyFunctions(categoryId);
Alignment al = getCurrentAlignment();
if (al != null) {
List<PropertyFunctionDefinition> cfs = new ArrayList<>();
for (CustomPropertyFunction cf : al.getAllCustomPropertyFunctions().values()) {
PropertyFunctionDefinition descriptor = cf.getDescriptor();
if (Objects.equal(categoryId, descriptor.getCategoryId())) {
cfs.add(new AlignmentFunctionDescriptor(descriptor));
}
}
cfs.addAll(functions);
functions = cfs;
}
return functions;
}
use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.
the class AbstractBaseAlignmentLoader method processBaseAlignments.
/**
* Creates and adds cells and modifiers of the base alignments to the main
* alignment.
*
* @param alignment the alignment to add base alignments to
* @param sourceTypes the source types to use for resolving definition
* references
* @param targetTypes the target types to use for resolving definition
* references
* @param prefixMapping gets filled with a mapping from local to global
* prefixes
* @param alignmentToInfo gets filled with a mapping from base alignment
* representations to prefixes and URIs
* @param reporter the I/O reporter to report any errors to, may be
* <code>null</code>
* @throws IOException if one of the base alignments does not have cell ids
*/
private void processBaseAlignments(MutableAlignment alignment, TypeIndex sourceTypes, TypeIndex targetTypes, Map<A, Map<String, String>> prefixMapping, Map<A, AlignmentInfo> alignmentToInfo, IOReporter reporter) throws IOException {
for (Entry<A, AlignmentInfo> base : alignmentToInfo.entrySet()) {
Collection<C> baseCells = getCells(base.getKey());
boolean hasIds = true;
for (C baseCell : baseCells) if (Strings.isNullOrEmpty(getCellId(baseCell))) {
hasIds = false;
break;
}
if (!hasIds) {
throw new IOException("At least one base alignment (" + base.getValue().uri.absoluteURI + ") has no cell ids. Please load and save it to generate them.");
}
}
for (Entry<A, AlignmentInfo> base : alignmentToInfo.entrySet()) {
if (alignment.getBaseAlignments().containsValue(base.getValue().uri.usedURI)) {
// base alignment already present
// can currently happen with base alignments included in base
// alignments
reporter.warn(new IOMessageImpl("Base alignment at " + base.getValue().uri.usedURI + " has already been added", null));
} else {
Collection<CustomPropertyFunction> baseFunctions = getPropertyFunctions(base.getKey(), sourceTypes, targetTypes);
Collection<C> baseCells = getCells(base.getKey());
Collection<BaseAlignmentCell> createdBaseCells = new ArrayList<BaseAlignmentCell>(baseCells.size());
List<MutableCell> createdCells = new ArrayList<>(baseCells.size());
for (C baseCell : baseCells) {
// add cells of base alignments
MutableCell cell = createCell(baseCell, sourceTypes, targetTypes, reporter);
if (cell != null) {
createdCells.add(cell);
}
}
// Migrate UnmigratedCells
migrateCells(createdCells, reporter);
for (MutableCell cell : createdCells) {
createdBaseCells.add(new BaseAlignmentCell(cell, base.getValue().uri.usedURI, base.getValue().prefix));
}
alignment.addBaseAlignment(base.getValue().prefix, base.getValue().uri.usedURI, createdBaseCells, baseFunctions);
}
}
// add modifiers of base alignments
for (Entry<A, AlignmentInfo> base : alignmentToInfo.entrySet()) applyModifiers(alignment, getModifiers(base.getKey()), prefixMapping.get(base.getKey()), base.getValue().prefix, true, reporter);
}
use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.
the class AbstractDefaultFunctionService method getCustomPropertyFunction.
private PropertyFunctionDefinition getCustomPropertyFunction(String id) {
Alignment al = getCurrentAlignment();
if (al != null) {
String localId = id;
if (localId.startsWith(PREFIX_ALIGNMENT_FUNCTION)) {
localId = localId.substring(PREFIX_ALIGNMENT_FUNCTION.length());
}
CustomPropertyFunction cf = al.getAllCustomPropertyFunctions().get(localId);
if (cf != null) {
return new AlignmentFunctionDescriptor(cf.getDescriptor());
}
}
return null;
}
use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.
the class AbstractDefaultTransformationFunctionService method getPropertyTransformations.
@Override
public List<PropertyTransformationFactory> getPropertyTransformations(String functionId) {
List<PropertyTransformationFactory> functions = super.getPropertyTransformations(functionId);
Alignment al = getCurrentAlignment();
if (al != null) {
List<PropertyTransformationFactory> cfs = new ArrayList<>(functions);
String localId = functionId;
if (localId.startsWith(PREFIX_ALIGNMENT_FUNCTION)) {
localId = localId.substring(PREFIX_ALIGNMENT_FUNCTION.length());
}
CustomPropertyFunction cf = al.getAllCustomPropertyFunctions().get(localId);
if (cf != null) {
cfs.add(new CustomPropertyFunctionFactory(cf));
}
functions = cfs;
}
return functions;
}
use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.
the class JaxbToAlignment method getPropertyFunctions.
@Override
protected Collection<CustomPropertyFunction> getPropertyFunctions(AlignmentType source, TypeIndex sourceTypes, TypeIndex targetTypes) {
LoadAlignmentContextImpl context = new LoadAlignmentContextImpl();
context.setSourceTypes(sourceTypes);
context.setTargetTypes(targetTypes);
Collection<CustomPropertyFunction> result = new ArrayList<>();
List<CustomFunctionType> functions = source.getCustomFunction();
if (functions != null) {
for (CustomFunctionType function : functions) {
Element elem = function.getAny();
if (elem != null) {
CustomPropertyFunction cf = HaleIO.getComplexValue(elem, CustomPropertyFunction.class, context);
if (cf != null) {
result.add(cf);
}
}
}
}
return result;
}
Aggregations