public IReason updateNeeded(IUpdateContext context) {
    // retrieve name from pictogram model
    String pictogramName = null;
    PictogramElement pictogramElement = context.getPictogramElement();
    if (pictogramElement instanceof ContainerShape) {
      ContainerShape cs = (ContainerShape) pictogramElement;
      for (Shape shape : cs.getChildren()) {
        if (shape.getGraphicsAlgorithm() instanceof Text) {
          Text text = (Text) shape.getGraphicsAlgorithm();
          pictogramName = text.getValue();
        }
      }
    }

    // retrieve name from business model
    String businessName = null;
    Object bo = getBusinessObjectForPictogramElement(pictogramElement);
    if (bo instanceof EClass) {
      EClass eClass = (EClass) bo;
      businessName = eClass.getName();
    }

    // update needed, if names are different
    boolean updateNameNeeded =
        ((pictogramName == null && businessName != null)
            || (pictogramName != null && !pictogramName.equals(businessName)));
    if (updateNameNeeded) {
      return Reason.createTrueReason("Name is out of date");
    } else {
      return Reason.createFalseReason();
    }
  }
Ejemplo n.º 2
0
 private static List<CoreMap> toTimexCoreMaps(Element docElem, CoreMap originalDocument) {
   // --Collect Token Offsets
   HashMap<Integer, Integer> beginMap = new HashMap<Integer, Integer>();
   HashMap<Integer, Integer> endMap = new HashMap<Integer, Integer>();
   boolean haveTokenOffsets = true;
   for (CoreMap sent : originalDocument.get(CoreAnnotations.SentencesAnnotation.class)) {
     for (CoreLabel token : sent.get(CoreAnnotations.TokensAnnotation.class)) {
       Integer tokBegin = token.get(CoreAnnotations.TokenBeginAnnotation.class);
       Integer tokEnd = token.get(CoreAnnotations.TokenEndAnnotation.class);
       if (tokBegin == null || tokEnd == null) {
         haveTokenOffsets = false;
       }
       int charBegin = token.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class);
       int charEnd = token.get(CoreAnnotations.CharacterOffsetEndAnnotation.class);
       beginMap.put(charBegin, tokBegin);
       endMap.put(charEnd, tokEnd);
     }
   }
   // --Set Timexes
   List<CoreMap> timexMaps = new ArrayList<CoreMap>();
   int offset = 0;
   Element textElem = docElem.getFirstChildElement("text");
   for (int i = 0; i < textElem.getChildCount(); i++) {
     Node content = textElem.getChild(i);
     if (content instanceof Text) {
       Text text = (Text) content;
       offset += text.getValue().length();
     } else if (content instanceof Element) {
       Element child = (Element) content;
       if (child.getLocalName().equals("TIMEX3")) {
         Timex timex = new Timex(child);
         if (child.getChildCount() != 1) {
           throw new RuntimeException("TIMEX3 should only contain text " + child);
         }
         String timexText = child.getValue();
         CoreMap timexMap = new ArrayCoreMap();
         // (timex)
         timexMap.set(TimexAnnotation.class, timex);
         // (text)
         timexMap.set(CoreAnnotations.TextAnnotation.class, timexText);
         // (characters)
         int charBegin = offset;
         timexMap.set(CoreAnnotations.CharacterOffsetBeginAnnotation.class, charBegin);
         offset += timexText.length();
         int charEnd = offset;
         timexMap.set(CoreAnnotations.CharacterOffsetEndAnnotation.class, charEnd);
         // (tokens)
         if (haveTokenOffsets) {
           Integer tokBegin = beginMap.get(charBegin);
           int searchStep = 1; // if no exact match, search around the character offset
           while (tokBegin == null) {
             tokBegin = beginMap.get(charBegin - searchStep);
             if (tokBegin == null) {
               tokBegin = beginMap.get(charBegin + searchStep);
             }
             searchStep += 1;
           }
           searchStep = 1;
           Integer tokEnd = endMap.get(charEnd);
           while (tokEnd == null) {
             tokEnd = endMap.get(charEnd - searchStep);
             if (tokEnd == null) {
               tokEnd = endMap.get(charEnd + searchStep);
             }
             searchStep += 1;
           }
           timexMap.set(CoreAnnotations.TokenBeginAnnotation.class, tokBegin);
           timexMap.set(CoreAnnotations.TokenEndAnnotation.class, tokEnd);
         }
         // (add)
         timexMaps.add(timexMap);
       } else {
         throw new RuntimeException("unexpected element " + child);
       }
     } else {
       throw new RuntimeException("unexpected content " + content);
     }
   }
   return timexMaps;
 }
Ejemplo n.º 3
0
  public Funding toFunding() {
    Funding result = new Funding();
    Amount orcidAmount = new Amount();
    if (!PojoUtil.isEmpty(amount)) orcidAmount.setContent(amount.getValue());
    if (!PojoUtil.isEmpty(currencyCode)) orcidAmount.setCurrencyCode(currencyCode.getValue());
    result.setAmount(orcidAmount);
    if (!PojoUtil.isEmpty(description)) result.setDescription(description.getValue());
    if (!PojoUtil.isEmpty(startDate)) result.setStartDate(new FuzzyDate(startDate.toFuzzyDate()));
    if (!PojoUtil.isEmpty(endDate)) result.setEndDate(new FuzzyDate(endDate.toFuzzyDate()));
    if (!PojoUtil.isEmpty(putCode)) result.setPutCode(Long.valueOf(putCode.getValue()));
    if (fundingTitle != null) {
      result.setTitle(fundingTitle.toFundingTitle());
    }
    if (!PojoUtil.isEmpty(fundingType))
      result.setType(FundingType.fromValue(fundingType.getValue()));

    if (organizationDefinedFundingSubType != null
        && !PojoUtil.isEmpty(organizationDefinedFundingSubType.getSubtype()))
      result.setOrganizationDefinedType(
          new OrganizationDefinedFundingSubType(
              organizationDefinedFundingSubType.getSubtype().getValue()));

    if (!PojoUtil.isEmpty(url)) result.setUrl(new Url(url.getValue()));
    else result.setUrl(new Url(""));
    if (visibility != null)
      result.setVisibility(
          org.orcid.jaxb.model.common_rc2.Visibility.fromValue(visibility.getVisibility().value()));

    // Set Organization
    Organization organization = new Organization();
    if (!PojoUtil.isEmpty(fundingName)) organization.setName(fundingName.getValue());
    OrganizationAddress organizationAddress = new OrganizationAddress();
    organization.setAddress(organizationAddress);
    if (!PojoUtil.isEmpty(city)) organizationAddress.setCity(city.getValue());
    if (!PojoUtil.isEmpty(region)) {
      organizationAddress.setRegion(region.getValue());
    }
    if (!PojoUtil.isEmpty(country)) {
      organizationAddress.setCountry(Iso3166Country.fromValue(country.getValue()));
    }
    if (!PojoUtil.isEmpty(disambiguatedFundingSourceId)) {
      organization.setDisambiguatedOrganization(new DisambiguatedOrganization());
      organization
          .getDisambiguatedOrganization()
          .setDisambiguatedOrganizationIdentifier(disambiguatedFundingSourceId.getValue());
      organization
          .getDisambiguatedOrganization()
          .setDisambiguationSource(disambiguationSource.getValue());
    }
    result.setOrganization(organization);

    // Set contributors
    if (contributors != null && !contributors.isEmpty()) {
      FundingContributors fContributors = new FundingContributors();
      for (Contributor contributor : contributors) {
        if (!PojoUtil.isEmtpy(contributor))
          fContributors.getContributor().add(contributor.toFundingContributor());
      }
      result.setContributors(fContributors);
    }
    // Set external identifiers
    if (externalIdentifiers != null && !externalIdentifiers.isEmpty()) {
      FundingExternalIdentifiers fExternalIdentifiers = new FundingExternalIdentifiers();
      for (FundingExternalIdentifierForm fExternalIdentifier : externalIdentifiers) {
        if (!PojoUtil.isEmtpy(fExternalIdentifier))
          fExternalIdentifiers
              .getExternalIdentifier()
              .add(fExternalIdentifier.toFundingExternalIdentifier());
      }
      result.setExternalIdentifiers(fExternalIdentifiers);
    }

    return result;
  }