コード例 #1
0
  public GraphTripliser(
      Queryable input,
      GraphMapping graphMapping,
      GraphNodeTripliserFactory graphNodeTripliserFactory,
      TripliserManager tripliserManager,
      QueryService queryService,
      GraphTagger graphTagger)
      throws InvalidGraphMappingException, IgnoredGraphMappingException {
    this.input = input;
    this.graphMapping = graphMapping;
    this.graphNodeTripliserFactory = graphNodeTripliserFactory;
    this.tripliserManager = tripliserManager;
    this.graphTagger = graphTagger;

    List<Node> graphNodeList = new ArrayList<Node>();
    graphNodeList.add(null);
    if (graphMapping.getQuery() != null) {
      try {
        graphNodeList =
            queryService.getNodes(input, graphMapping, null, tripliserManager.getGraphContext());
      } catch (QueryException e) {
        throw new InvalidGraphMappingException("Invalid graph query", e);
      }
      if (graphNodeList.isEmpty()) {
        if (graphMapping.isRequired())
          throw new InvalidGraphMappingException(
              "A required graph's query must return at least one result");
        else
          throw new IgnoredGraphMappingException(
              "A non-required graph's query returned no results");
      }
    }

    graphNodes = graphNodeList.iterator();
  }
コード例 #2
0
  public void provideNamesForUnamedMappings(Mapping mapping) throws TripliserException {
    Set<String> usedNames = new HashSet<String>();

    List<GraphMapping> graphMappings = mapping.getGraphMappings();

    for (GraphMapping graphMapping : graphMappings) {
      if (graphMapping.getName() == null) {
        graphMapping.setName(createNewGraphName("graph", usedNames));
      } else {
        usedNames.add(graphMapping.getName());
      }

      List<ResourceMapping> resourceMappings = graphMapping.getResourceMappings();
      for (ResourceMapping resourceMapping : resourceMappings) {
        if (resourceMapping.getName() == null) {
          resourceMapping.setName(createNewResourceName("resource", usedNames));
        } else {
          usedNames.add(resourceMapping.getName());
        }
      }
    }
  }