@Test void resolveUnitLabelWithUnit_directUnitMatch() { Attribute attr = attrMetaFactory.create().setName("attr").setLabel("weight (kg)").setDescription(null); Unit<? extends Quantity> unit = unitResolverImpl.resolveUnit(attr); assertEquals(valueOf("kg"), unit); }
@Override public Unit<? extends Quantity> resolveUnit(Attribute attr) { Set<String> tokens = tokenize(attr.getLabel(), attr.getDescription()); Unit<? extends Quantity> unit = null; if (!tokens.isEmpty()) { for (String term : tokens) { try { unit = Unit.valueOf(term); break; } catch (IllegalArgumentException e) { } } if (isUnitEmpty(unit)) { OntologyTerm unitOntologyTerm = resolveUnitOntologyTerm( tokens.stream() .map(this::convertNumberToOntologyTermStyle) .collect(Collectors.toSet())); if (unitOntologyTerm != null) { for (String synonymLabel : unitOntologyTerm.getSynonyms()) { try { unit = Unit.valueOf(synonymLabel); break; } catch (IllegalArgumentException e) { } } } } } if (isUnitEmpty(unit)) { unit = null; } return unit; }
UnitResolverImpl implements UnitResolver { @Override public Unit<? extends Quantity> resolveUnit(Attribute attr) { Set<String> tokens = tokenize(attr.getLabel(), attr.getDescription()); Unit<? extends Quantity> unit = null; if (!tokens.isEmpty()) { for (String term : tokens) { try { unit = Unit.valueOf(term); break; } catch (IllegalArgumentException e) { } } if (isUnitEmpty(unit)) { OntologyTerm unitOntologyTerm = resolveUnitOntologyTerm( tokens.stream() .map(this::convertNumberToOntologyTermStyle) .collect(Collectors.toSet())); if (unitOntologyTerm != null) { for (String synonymLabel : unitOntologyTerm.getSynonyms()) { try { unit = Unit.valueOf(synonymLabel); break; } catch (IllegalArgumentException e) { } } } } } if (isUnitEmpty(unit)) { unit = null; } return unit; } }
UnitResolverImpl implements UnitResolver { @Override public Unit<? extends Quantity> resolveUnit(Attribute attr) { Set<String> tokens = tokenize(attr.getLabel(), attr.getDescription()); Unit<? extends Quantity> unit = null; if (!tokens.isEmpty()) { for (String term : tokens) { try { unit = Unit.valueOf(term); break; } catch (IllegalArgumentException e) { } } if (isUnitEmpty(unit)) { OntologyTerm unitOntologyTerm = resolveUnitOntologyTerm( tokens.stream() .map(this::convertNumberToOntologyTermStyle) .collect(Collectors.toSet())); if (unitOntologyTerm != null) { for (String synonymLabel : unitOntologyTerm.getSynonyms()) { try { unit = Unit.valueOf(synonymLabel); break; } catch (IllegalArgumentException e) { } } } } } if (isUnitEmpty(unit)) { unit = null; } return unit; } UnitResolverImpl(OntologyService ontologyService); }
UnitResolverImpl implements UnitResolver { @Override public Unit<? extends Quantity> resolveUnit(Attribute attr) { Set<String> tokens = tokenize(attr.getLabel(), attr.getDescription()); Unit<? extends Quantity> unit = null; if (!tokens.isEmpty()) { for (String term : tokens) { try { unit = Unit.valueOf(term); break; } catch (IllegalArgumentException e) { } } if (isUnitEmpty(unit)) { OntologyTerm unitOntologyTerm = resolveUnitOntologyTerm( tokens.stream() .map(this::convertNumberToOntologyTermStyle) .collect(Collectors.toSet())); if (unitOntologyTerm != null) { for (String synonymLabel : unitOntologyTerm.getSynonyms()) { try { unit = Unit.valueOf(synonymLabel); break; } catch (IllegalArgumentException e) { } } } } } if (isUnitEmpty(unit)) { unit = null; } return unit; } UnitResolverImpl(OntologyService ontologyService); @Override Unit<? extends Quantity> resolveUnit(Attribute attr); }
UnitResolverImpl implements UnitResolver { @Override public Unit<? extends Quantity> resolveUnit(Attribute attr) { Set<String> tokens = tokenize(attr.getLabel(), attr.getDescription()); Unit<? extends Quantity> unit = null; if (!tokens.isEmpty()) { for (String term : tokens) { try { unit = Unit.valueOf(term); break; } catch (IllegalArgumentException e) { } } if (isUnitEmpty(unit)) { OntologyTerm unitOntologyTerm = resolveUnitOntologyTerm( tokens.stream() .map(this::convertNumberToOntologyTermStyle) .collect(Collectors.toSet())); if (unitOntologyTerm != null) { for (String synonymLabel : unitOntologyTerm.getSynonyms()) { try { unit = Unit.valueOf(synonymLabel); break; } catch (IllegalArgumentException e) { } } } } } if (isUnitEmpty(unit)) { unit = null; } return unit; } UnitResolverImpl(OntologyService ontologyService); @Override Unit<? extends Quantity> resolveUnit(Attribute attr);  }