コード例 #1
0
ファイル: DictionaryTagger.java プロジェクト: oaqa/banner
 // TODO Determine how to combine this with loading
 public void configure(HierarchicalConfiguration config, Tokenizer tokenizer) {
   HierarchicalConfiguration localConfig = config.configurationAt(this.getClass().getName());
   filterContainedMentions = localConfig.getBoolean("filterContainedMentions", false);
   normalizeMixedCase = localConfig.getBoolean("normalizeMixedCase", false);
   normalizeDigits = localConfig.getBoolean("normalizeDigits", false);
   generate2PartVariations = localConfig.getBoolean("generate2PartVariations", false);
   dropEndParentheticals = localConfig.getBoolean("dropEndParentheticals", false);
   this.tokenizer = tokenizer;
 }
コード例 #2
0
ファイル: ScriptParam.java プロジェクト: roxberry/zaproxy
  @Override
  protected void parse() {
    defaultScript = getConfig().getString(PARAM_DEFAULT_SCRIPT, "");
    defaultDir = getConfig().getString(PARAM_DEFAULT_DIR, "");

    try {
      List<HierarchicalConfiguration> fields =
          ((HierarchicalConfiguration) getConfig()).configurationsAt(ALL_SCRIPTS_KEY);
      this.scripts = new HashSet<>(fields.size());
      List<String> tempListNames = new ArrayList<>(fields.size());
      for (HierarchicalConfiguration sub : fields) {
        String name = sub.getString(SCRIPT_NAME_KEY, "");
        try {
          if (!"".equals(name) && !tempListNames.contains(name)) {
            tempListNames.add(name);

            File file = new File(sub.getString(SCRIPT_FILE_KEY));
            if (!file.exists()) {
              logger.error("Script '" + file.getAbsolutePath() + "' does not exist");
              continue;
            }

            ScriptWrapper script =
                new ScriptWrapper(
                    sub.getString(SCRIPT_NAME_KEY),
                    sub.getString(SCRIPT_DESC_KEY),
                    sub.getString(SCRIPT_ENGINE_KEY),
                    sub.getString(SCRIPT_TYPE_KEY),
                    sub.getBoolean(SCRIPT_ENABLED_KEY),
                    file);

            script.setLoadOnStart(true); // Because it was saved ;)

            scripts.add(script);
          }
        } catch (Exception e) {
          logger.error("Error while loading the script: " + name, e);
        }
      }
    } catch (Exception e) {
      logger.error("Error while loading the scripts: " + e.getMessage(), e);
    }

    try {
      this.scriptDirs = new ArrayList<File>();
      for (Object dirName : getConfig().getList(SCRIPT_DIRS)) {
        File f = new File((String) dirName);
        if (!f.exists() || !f.isDirectory()) {
          logger.error("Not a valid script directory: " + dirName);
        } else {
          scriptDirs.add(f);
        }
      }

    } catch (Exception e) {
      logger.error("Error while loading the script dirs: " + e.getMessage(), e);
    }
    confirmRemoveDir = getConfig().getBoolean(SCRIPT_CONFIRM_REMOVE_DIR, true);
  }
コード例 #3
0
  private Graph getGraphFromConfiguration(final HierarchicalConfiguration graphConfiguration)
      throws GraphConfigurationException {
    String graphConfigurationType = graphConfiguration.getString(Tokens.REXSTER_GRAPH_TYPE);
    final boolean isReadOnly = graphConfiguration.getBoolean(Tokens.REXSTER_GRAPH_READ_ONLY, false);

    if (graphConfigurationType.equals("neo4jgraph")) {
      graphConfigurationType = Neo4jGraphConfiguration.class.getName();
    } else if (graphConfigurationType.equals("orientgraph")) {
      graphConfigurationType = OrientGraphConfiguration.class.getName();
    } else if (graphConfigurationType.equals("tinkergraph")) {
      graphConfigurationType = TinkerGraphGraphConfiguration.class.getName();
    } else if (graphConfigurationType.equals("rexstergraph")) {
      graphConfigurationType = RexsterGraphGraphConfiguration.class.getName();
    } else if (graphConfigurationType.equals("memorystoresailgraph")) {
      graphConfigurationType = MemoryStoreSailGraphConfiguration.class.getName();
    } else if (graphConfigurationType.equals("nativestoresailgraph")) {
      graphConfigurationType = NativeStoreSailGraphConfiguration.class.getName();
    } else if (graphConfigurationType.equals("sparqlrepositorysailgraph")) {
      graphConfigurationType = SparqlRepositorySailGraphConfiguration.class.getName();
    } else if (graphConfigurationType.equals("dexgraph")) {
      graphConfigurationType = DexGraphConfiguration.class.getName();
    }

    final Graph graph;
    try {
      final Class clazz =
          Class.forName(
              graphConfigurationType, true, Thread.currentThread().getContextClassLoader());
      final GraphConfiguration graphConfigInstance = (GraphConfiguration) clazz.newInstance();
      Graph readWriteGraph = graphConfigInstance.configureGraphInstance(graphConfiguration);

      if (isReadOnly) {
        // the graph is configured to be readonly so wrap it up
        if (readWriteGraph instanceof IndexableGraph) {
          graph = new ReadOnlyIndexableGraph((IndexableGraph) readWriteGraph);
        } else {
          graph = new ReadOnlyGraph(readWriteGraph);
        }
      } else {
        graph = readWriteGraph;
      }

    } catch (NoClassDefFoundError err) {
      throw new GraphConfigurationException(
          String.format(
              "GraphConfiguration [%s] could not instantiate a class [%s].  Ensure that it is in Rexster's path.",
              graphConfigurationType, err.getMessage()));
    } catch (Exception ex) {
      throw new GraphConfigurationException(
          String.format(
              "GraphConfiguration could not be found or otherwise instantiated: [%s]. Ensure that it is in Rexster's path.",
              graphConfigurationType),
          ex);
    }

    return graph;
  }
コード例 #4
0
  public GraphConfigurationContainer(final List<HierarchicalConfiguration> configurations)
      throws GraphConfigurationException {

    if (configurations == null) {
      throw new GraphConfigurationException("No graph configurations");
    }

    // create one graph for each configuration for each <graph> element
    final Iterator<HierarchicalConfiguration> it = configurations.iterator();
    while (it.hasNext()) {
      final HierarchicalConfiguration graphConfig = it.next();
      final String graphName = graphConfig.getString(Tokens.REXSTER_GRAPH_NAME, "");

      if (graphName.equals("")) {
        // all graphs must have a graph name
        logger.warn("Could not load graph " + graphName + ".  The graph-name element was not set.");
        this.failedConfigurations.add(graphConfig);
      } else {
        // check for duplicate graph configuration
        if (!this.graphs.containsKey(graphName)) {

          if (graphConfig.getBoolean(Tokens.REXSTER_GRAPH_ENABLED, true)) {

            // one graph failing initialization will not prevent the rest in
            // their attempt to be created
            try {
              final Graph graph = getGraphFromConfiguration(graphConfig);
              final RexsterApplicationGraph rag = new RexsterApplicationGraph(graphName, graph);

              // loads extensions that are allowed to be served for this graph
              final List extensionConfigs =
                  graphConfig.getList(Tokens.REXSTER_GRAPH_EXTENSIONS_ALLOWS_PATH);
              rag.loadAllowableExtensions(extensionConfigs);

              // loads extension configuration for this graph
              final List<HierarchicalConfiguration> extensionConfigurations =
                  graphConfig.configurationsAt(Tokens.REXSTER_GRAPH_EXTENSIONS_PATH);
              rag.loadExtensionsConfigurations(extensionConfigurations);

              this.graphs.put(rag.getGraphName(), rag);

              logger.info("Graph " + graphName + " - " + graph + " loaded");
            } catch (GraphConfigurationException gce) {
              logger.warn(
                  "Could not load graph " + graphName + ". Please check the XML configuration.");
              logger.warn(gce.getMessage());

              if (gce.getCause() != null) {
                logger.warn(gce.getCause().getMessage());
              }

              failedConfigurations.add(graphConfig);
            } catch (Exception e) {
              logger.warn("Could not load graph " + graphName + ".", e);

              failedConfigurations.add(graphConfig);
            }
          } else {
            logger.info("Graph " + graphName + " - " + " not enabled and not loaded.");
          }
        } else {
          logger.warn(
              "A graph with the name "
                  + graphName
                  + " was already configured.  Please check the XML configuration.");

          failedConfigurations.add(graphConfig);
        }
      }
    }
  }
コード例 #5
0
ファイル: VrpXMLReader.java プロジェクト: heerad/jsprit
  private void readVehiclesAndTheirTypes(XMLConfiguration vrpProblem) {

    // read vehicle-types
    Map<String, VehicleType> types = new HashMap<String, VehicleType>();
    List<HierarchicalConfiguration> typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type");
    for (HierarchicalConfiguration typeConfig : typeConfigs) {
      String typeId = typeConfig.getString("id");
      if (typeId == null) throw new IllegalStateException("typeId is missing.");

      String capacityString = typeConfig.getString("capacity");
      boolean capacityDimensionsExist = typeConfig.containsKey("capacity-dimensions.dimension(0)");
      if (capacityString == null && !capacityDimensionsExist) {
        throw new IllegalStateException("capacity of type is not set. use 'capacity-dimensions'");
      }
      if (capacityString != null && capacityDimensionsExist) {
        throw new IllegalStateException(
            "either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
      }

      VehicleTypeImpl.Builder typeBuilder;
      if (capacityString != null) {
        typeBuilder =
            VehicleTypeImpl.Builder.newInstance(typeId)
                .addCapacityDimension(0, Integer.parseInt(capacityString));
      } else {
        typeBuilder = VehicleTypeImpl.Builder.newInstance(typeId);
        List<HierarchicalConfiguration> dimensionConfigs =
            typeConfig.configurationsAt("capacity-dimensions.dimension");
        for (HierarchicalConfiguration dimension : dimensionConfigs) {
          Integer index = dimension.getInt("[@index]");
          Integer value = dimension.getInt("");
          typeBuilder.addCapacityDimension(index, value);
        }
      }
      Double fix = typeConfig.getDouble("costs.fixed");
      Double timeC = typeConfig.getDouble("costs.time");
      Double distC = typeConfig.getDouble("costs.distance");

      if (fix != null) typeBuilder.setFixedCost(fix);
      if (timeC != null) typeBuilder.setCostPerTime(timeC);
      if (distC != null) typeBuilder.setCostPerDistance(distC);
      VehicleType type = typeBuilder.build();
      String id = type.getTypeId();
      String penalty = typeConfig.getString("[@type]");
      if (penalty != null) {
        if (penalty.equals("penalty")) {
          String penaltyFactor = typeConfig.getString("[@penaltyFactor]");
          if (penaltyFactor != null) {
            type = new PenaltyVehicleType(type, Double.parseDouble(penaltyFactor));
          } else type = new PenaltyVehicleType(type);
          id = id + "_penalty";
        }
      }

      types.put(id, type);
    }

    // read vehicles
    List<HierarchicalConfiguration> vehicleConfigs =
        vrpProblem.configurationsAt("vehicles.vehicle");
    boolean doNotWarnAgain = false;
    for (HierarchicalConfiguration vehicleConfig : vehicleConfigs) {
      String vehicleId = vehicleConfig.getString("id");
      if (vehicleId == null) throw new IllegalStateException("vehicleId is missing.");
      Builder builder = VehicleImpl.Builder.newInstance(vehicleId);
      String typeId = vehicleConfig.getString("typeId");
      if (typeId == null) throw new IllegalStateException("typeId is missing.");
      String vType = vehicleConfig.getString("[@type]");
      if (vType != null) {
        if (vType.equals("penalty")) {
          typeId += "_penalty";
        }
      }
      VehicleType type = types.get(typeId);
      if (type == null)
        throw new IllegalStateException("vehicleType with typeId " + typeId + " is missing.");
      builder.setType(type);
      String locationId = vehicleConfig.getString("location.id");
      if (locationId == null) {
        locationId = vehicleConfig.getString("startLocation.id");
      }
      if (locationId == null) throw new IllegalStateException("location.id is missing.");
      builder.setStartLocationId(locationId);
      String coordX = vehicleConfig.getString("location.coord[@x]");
      String coordY = vehicleConfig.getString("location.coord[@y]");
      if (coordX == null || coordY == null) {
        coordX = vehicleConfig.getString("startLocation.coord[@x]");
        coordY = vehicleConfig.getString("startLocation.coord[@y]");
      }
      if (coordX == null || coordY == null) {
        if (!doNotWarnAgain) {
          logger.warn("location.coord is missing. will not warn you again.");
          doNotWarnAgain = true;
        }
      } else {
        Coordinate coordinate =
            Coordinate.newInstance(Double.parseDouble(coordX), Double.parseDouble(coordY));
        builder.setStartLocationCoordinate(coordinate);
      }

      String endLocationId = vehicleConfig.getString("endLocation.id");
      if (endLocationId != null) builder.setEndLocationId(endLocationId);
      String endCoordX = vehicleConfig.getString("endLocation.coord[@x]");
      String endCoordY = vehicleConfig.getString("endLocation.coord[@y]");
      if (endCoordX == null || endCoordY == null) {
        if (!doNotWarnAgain) {
          logger.warn("endLocation.coord is missing. will not warn you again.");
          doNotWarnAgain = true;
        }
      } else {
        Coordinate coordinate =
            Coordinate.newInstance(Double.parseDouble(endCoordX), Double.parseDouble(endCoordY));
        builder.setEndLocationCoordinate(coordinate);
      }

      String start = vehicleConfig.getString("timeSchedule.start");
      String end = vehicleConfig.getString("timeSchedule.end");
      if (start != null) builder.setEarliestStart(Double.parseDouble(start));
      if (end != null) builder.setLatestArrival(Double.parseDouble(end));
      String returnToDepot = vehicleConfig.getString("returnToDepot");
      if (returnToDepot != null) {
        builder.setReturnToDepot(vehicleConfig.getBoolean("returnToDepot"));
      }
      VehicleImpl vehicle = builder.build();
      vrpBuilder.addVehicle(vehicle);
      vehicleMap.put(vehicleId, vehicle);
    }
  }