コード例 #1
0
ファイル: EadImporter.java プロジェクト: EHRI/ehri-rest
  /**
   * Subclasses can override this method to cater to their special needs for
   * UndeterminedRelationships by default, it expects something like this in the original EAD:
   *
   * <p>
   *
   * <pre>{@code
   * <persname source="terezin-victims" authfilenumber="PERSON.ITI.1514982">Kien,
   * Leonhard (* 11.5.1886)</persname>
   * }</pre>
   *
   * <p>it works in unison with the extractRelations() method.
   *
   * @param unit the current unit
   */
  protected void solveUndeterminedRelationships(DocumentaryUnit unit) throws ValidationError {
    // Try to resolve the undetermined relationships
    // we can only create the annotations after the DocumentaryUnit
    // and its Description have been added to the graph,
    // so they have IDs.
    Api api = ApiFactory.noLogging(framedGraph, actioner.as(UserProfile.class));
    Bundle linkBundle =
        new Bundle(EntityClass.LINK)
            .withDataValue(Ontology.LINK_HAS_DESCRIPTION, RESOLVED_LINK_DESC);

    for (Description desc : unit.getDescriptions()) {
      // Put the set of relationships into a HashSet to remove duplicates.
      for (AccessPoint rel : Sets.newHashSet(desc.getAccessPoints())) {
        // the wp2 undetermined relationship that can be resolved have a 'cvoc' and a 'concept'
        // attribute.
        // they need to be found in the vocabularies that are in the graph
        if (rel.getPropertyKeys().contains("cvoc")) {
          String vocab = rel.getProperty("cvoc");
          String conceptId = rel.getProperty("concept");
          if (conceptId == null) {
            conceptId = rel.getProperty("target");
          }
          logger.debug("cvoc: {}, concept: {}", vocab, conceptId);
          try {
            Vocabulary vocabulary = manager.getEntity(vocab, Vocabulary.class);
            for (Concept concept : vocabulary.getConcepts()) {
              logger.debug("********************* {} {}", concept.getId(), concept.getIdentifier());
              if (concept.getIdentifier().equalsIgnoreCase(conceptId)) {
                try {
                  // TODO: Fix link type here...
                  Bundle data = linkBundle.withDataValue(Ontology.LINK_HAS_TYPE, "associative");
                  Link link = api.create(data, Link.class);
                  unit.addLink(link);
                  concept.addLink(link);
                  link.addLinkBody(rel);
                  logger.debug("link created between {} and {}", conceptId, concept.getId());
                } catch (PermissionDenied | DeserializationError ex) {
                  logger.error(ex.getMessage());
                }
              }
            }
          } catch (ItemNotFound ex) {
            logger.error("Vocabulary with id {} not found: {}", vocab, ex.getMessage());
          }
        } else {
          logger.debug("no cvoc found");
        }
      }
    }
  }
コード例 #2
0
 @Test
 public void testCreateLink() throws Exception {
   DocumentaryUnit src = manager.getFrame("c1", DocumentaryUnit.class);
   HistoricalAgent dst = manager.getFrame("a1", HistoricalAgent.class);
   UndeterminedRelationship rel = manager.getFrame("ur1", UndeterminedRelationship.class);
   String linkDesc = "Test Link";
   String linkType = "subjectAccess";
   Bundle linkBundle = getLinkBundle(linkDesc, linkType);
   Link link = linkViews.createLink("c1", "a1", Lists.newArrayList("ur1"), linkBundle, validUser);
   assertEquals(linkDesc, link.getDescription());
   assertEquals(2L, Iterables.size(link.getLinkTargets()));
   assertTrue(Iterables.contains(link.getLinkTargets(), src));
   assertTrue(Iterables.contains(link.getLinkTargets(), dst));
   assertEquals(1L, Iterables.size(link.getLinkBodies()));
   assertTrue(Iterables.contains(link.getLinkBodies(), rel));
 }
コード例 #3
0
 @Test
 public void testCreateAccessPointLink() throws Exception {
   DocumentaryUnit src = manager.getFrame("c1", DocumentaryUnit.class);
   HistoricalAgent dst = manager.getFrame("a1", HistoricalAgent.class);
   DocumentDescription desc = manager.getFrame("cd1", DocumentDescription.class);
   String linkDesc = "Test Link";
   String linkType = "subjectAccess";
   Bundle linkBundle = getLinkBundle(linkDesc, linkType);
   Link link =
       linkViews.createAccessPointLink(
           "c1", "a1", "cd1", linkDesc, linkType, linkBundle, validUser);
   assertEquals(linkDesc, link.getDescription());
   assertEquals(2L, Iterables.size(link.getLinkTargets()));
   assertTrue(Iterables.contains(link.getLinkTargets(), src));
   assertTrue(Iterables.contains(link.getLinkTargets(), dst));
   assertEquals(1L, Iterables.size(link.getLinkBodies()));
   UndeterminedRelationship rel =
       manager.cast(link.getLinkBodies().iterator().next(), UndeterminedRelationship.class);
   assertEquals(rel.getName(), linkDesc);
   assertEquals(rel.getRelationshipType(), linkType);
   Description d = rel.getDescription();
   assertEquals(desc, d);
 }