Exemplo n.º 1
0
  @Override
  public void type(
      Resource type,
      List<Pair<Resource, XSDDatatype>> simpleProperties,
      List<Pair<Resource, Object>> linkProperties,
      List<Pair<Resource, String>> geometryProperties)
      throws IOException {
    requestResponse.setFeatureIri(type);

    log.debug("[fe] registering (generic) output type for " + type);

    /*
     * List<String> layerSelectedProperties = layer
     * .getSelectedFeatureParams(session.getLanguage());
     */
    selectedProperties.add(0, "__fid");
    log.debug("- Property:" + "__fid" + " as 0");
    for (Pair<Resource, XSDDatatype> prop : simpleProperties) {

      log.debug("- Property:" + prop.getKey() + " as " + selectedProperties.size());
      selectedPropertiesIndex.put(prop.getKey(), selectedProperties.size());
      selectedProperties.add(prop.getKey().getLocalPart());
    }
    selectedProperties.add("__centerX");
    log.debug("- Property:" + "__centerX" + " as " + selectedProperties.size());
    selectedProperties.add("__centerY");
    log.debug("- Property:" + "__centerY" + " as " + selectedProperties.size());
  }
  /* (non-Javadoc)
   * @see forge.control.home.IControlSubmenu#update()
   */
  @Override
  public void update() {
    updating =
        true; // prevent itemStateChanged causing prefs to be saved or other logic occurring while
    // updating values

    this.view = VSubmenuPreferences.SINGLETON_INSTANCE;
    this.prefs = FModel.getPreferences();

    setPlayerNameButtonText();
    view.getCbDevMode().setSelected(ForgePreferences.DEV_MODE);
    view.getCbEnableMusic().setSelected(prefs.getPrefBoolean(FPref.UI_ENABLE_MUSIC));

    for (final Pair<JCheckBox, FPref> kv : lstControls) {
      kv.getKey().setSelected(prefs.getPrefBoolean(kv.getValue()));
    }
    view.reloadShortcuts();

    SwingUtilities.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            view.getCbRemoveSmall().requestFocusInWindow();
          }
        });

    updating = false;
  }
  public void processVectors(
      List<Pair<Integer, NamedVector>> vectors, boolean train, SequenceFile.Writer writer)
      throws IOException {

    BytesWritable recordKey = new BytesWritable("".getBytes());
    Text value = new Text();

    if (train) Collections.shuffle(vectors);

    double mu = -1.0;
    double ll = -1.0;
    int actual = -1;
    for (Pair<Integer, NamedVector> pair : vectors) {
      NamedVector v = pair.getValue();
      if (train) {
        actual = pair.getKey();
        mu = Math.min(this.k + 1, 200);
        ll = learningAlgorithm.logLikelihood(actual, v);
        this.averageLL = this.averageLL + (ll - this.averageLL) / mu;
      }

      Vector p = new DenseVector(LABELS);
      learningAlgorithm.classifyFull(p, v);
      int estimated = p.maxValueIndex();
      this.counts[estimated]++;

      if (writer != null) {
        value.set(
            String.format(
                "%s%c%d%c01%f",
                v.getName(),
                SEQUENCE_FILE_FIELD_SEPARATOR,
                estimated,
                SEQUENCE_FILE_FIELD_SEPARATOR,
                p.get(estimated)));
        writer.append(recordKey, value);
      }

      if (train) {
        int correct = (estimated == actual ? 1 : 0);
        this.averageCorrect = this.averageCorrect + (correct - this.averageCorrect) / mu;

        learningAlgorithm.train(actual, v);
        learningAlgorithm.close();
      }
      this.k++;
      int bump = this.BUMPS[(int) Math.floor(this.step) % this.BUMPS.length];
      int scale = (int) Math.pow(10, Math.floor(this.step / this.BUMPS.length));
      if (this.k % Math.min(MAX_STEP, bump * scale) == 0) {
        this.step += 0.25;
        if (train)
          System.out.printf(
              "%10d %10.3f %10.3f %10.2f %d\n",
              this.k, ll, this.averageLL, this.averageCorrect * 100, estimated);
        else System.out.printf("%c%10d, per label: %s\n", CR, this.k, Arrays.toString(this.counts));
      }
    }
  }
 private String formatAmbiguousDependencies(List<Pair<Dependency, File>> ambiguousDependencies) {
   StringBuilder msgSb = new StringBuilder();
   for (Pair<Dependency, File> pair : ambiguousDependencies) {
     msgSb.append("BOM " + pair.getValue() + " defines version " + pair.getKey().getVersion());
     msgSb.append(LINE_SEPARATOR);
     msgSb.append(LINE_SEPARATOR);
   }
   return msgSb.toString();
 }
Exemplo n.º 5
0
  private static GalenPageAction checkActionFrom(String[] args, String originalText) {
    CommandLineReader reader = new CommandLineReader(args);

    String specPath = null;
    List<String> includedTags = new LinkedList<>();
    List<String> excludedTags = new LinkedList<>();
    Map<String, Object> jsVariables = new HashMap<>();

    // Skipping the check action name
    reader.skipArgument();

    while (reader.hasNext()) {
      if (!reader.isNextArgument()) {
        specPath = reader.readNext();
      } else {
        Pair<String, String> argument = reader.readArgument();

        if (argument.getKey().equals("include")) {
          includedTags.addAll(readTags(argument.getValue()));
        } else if (argument.getKey().equals("exclude")) {
          excludedTags.addAll(readTags(argument.getValue()));
        } else if (argument.getKey().startsWith("V")) {
          String varName = argument.getKey().substring(1);
          String varValue = argument.getValue();
          jsVariables.put(varName, varValue);
        } else {
          throw new SyntaxException("Unknown argument: " + argument.getKey());
        }
      }
    }

    if (specPath == null || specPath.isEmpty()) {
      throw new SyntaxException("Missing spec path");
    }

    return new GalenPageActionCheck()
        .withSpec(specPath)
        .withIncludedTags(includedTags)
        .withExcludedTags(excludedTags)
        .withJsVariables(jsVariables);
  }
Exemplo n.º 6
0
 @Override
 protected void doMoveOnGenuineVariables(ScoreDirector scoreDirector) {
   for (Map.Entry<GenuineVariableDescriptor<Solution_>, List<Pair<Object, Object>>> entry :
       changeMap.entrySet()) {
     GenuineVariableDescriptor<Solution_> variableDescriptor = entry.getKey();
     for (Pair<Object, Object> pair : entry.getValue()) {
       Object entity = pair.getKey();
       Object value = pair.getValue();
       scoreDirector.changeVariableFacade(variableDescriptor, entity, value);
     }
   }
 }
  private Pair<PageRule, Map<String, String>> findAndProcessRule(
      String ruleText, StructNode ruleNode) {
    for (Pair<Rule, PageRule> rulePair : pageSpecHandler.getPageRules()) {
      Matcher matcher = rulePair.getKey().getPattern().matcher(ruleText);
      if (matcher.matches()) {
        int index = 1;

        Map<String, String> parameters = new HashMap<String, String>();

        for (String parameterName : rulePair.getKey().getParameters()) {
          String value = matcher.group(index);
          pageSpecHandler.setGlobalVariable(parameterName, value, ruleNode);

          parameters.put(parameterName, value);
          index += 1;
        }

        return new ImmutablePair<PageRule, Map<String, String>>(rulePair.getValue(), parameters);
      }
    }
    throw new SyntaxException(ruleNode, "Could find rule matching: " + ruleText);
  }
 public void visit() {
   // add root element (package) to stack
   stack.add(new MutablePair<>(astModel, 0));
   // manually handle it; root package doesn't have parent
   onStart(astModel);
   while (!stack.isEmpty()) {
     // get reference to parent element
     Pair<AstElement, Integer> currentPair = stack.peek();
     Integer index = currentPair.getValue();
     AstElement child = currentPair.getKey().get(index);
     // if not all children are processed...
     if (child != NoElement.instance()) {
       // handle one child
       onStart(child);
       currentPair.setValue(index + 1);
       // and go deeper
       stack.push(new MutablePair<>(child, 0));
     } else {
       // all children are processed, remove reference to parent
       // and say goodbye...
       onEnd(stack.pop().getKey());
     }
   }
 }
Exemplo n.º 9
0
 public PartitionChangeMove<Solution_> relocate(
     InnerScoreDirector<Solution_> destinationScoreDirector) {
   Map<GenuineVariableDescriptor<Solution_>, List<Pair<Object, Object>>> destinationChangeMap =
       new LinkedHashMap<>(changeMap.size());
   for (Map.Entry<GenuineVariableDescriptor<Solution_>, List<Pair<Object, Object>>> entry :
       changeMap.entrySet()) {
     GenuineVariableDescriptor<Solution_> variableDescriptor = entry.getKey();
     List<Pair<Object, Object>> originPairList = entry.getValue();
     List<Pair<Object, Object>> destinationPairList = new ArrayList<>(originPairList.size());
     for (Pair<Object, Object> pair : originPairList) {
       Object originEntity = pair.getKey();
       Object destinationEntity = destinationScoreDirector.locateWorkingObject(originEntity);
       if (destinationEntity == null && originEntity != null) {
         throw new IllegalStateException(
             "The destinationEntity ("
                 + destinationEntity
                 + ") cannot be null if the originEntity ("
                 + originEntity
                 + ") is not null.");
       }
       Object originValue = pair.getValue();
       Object destinationValue = destinationScoreDirector.locateWorkingObject(originValue);
       if (destinationValue == null && originValue != null) {
         throw new IllegalStateException(
             "The destinationValue ("
                 + destinationValue
                 + ") cannot be null if the originValue ("
                 + originValue
                 + ") is not null.");
       }
       destinationPairList.add(Pair.of(destinationEntity, destinationValue));
     }
     destinationChangeMap.put(variableDescriptor, destinationPairList);
   }
   return new PartitionChangeMove<>(destinationChangeMap);
 }
Exemplo n.º 10
0
 @Override
 public String getGroupName(Pair<ItemStack, Integer> object) {
   return "Count " + object.getKey().stackSize;
 }
Exemplo n.º 11
0
 public Pair<int[], int[]> compute() throws SQLException {
   Pair<int[], int[]> operand = parameters_.term_.term().result();
   operand = Pair.of(operand.getKey().clone(), operand.getValue().clone());
   CountAggregator.sortByCountDesc(operand.getKey(), operand.getValue());
   return operand;
 }
Exemplo n.º 12
0
  public void vertex(
      Resource iri,
      Resource type,
      List<Pair<Resource, Object>> simpleProperties,
      List<Pair<Resource, Object>> linkProperties,
      List<Pair<Resource, Geometry>> geometryProperties)
      throws IOException {

    SimpleFeatureBuilder sfb = getAndSetFeatureBuilder(type);
    List<SimpleFeature> sfc = getAndSetListSimpleFeature(type);

    for (Pair<Resource, Geometry> geomPair : geometryProperties) {
      Geometry geom = geomPair.getValue();

      try {
        geom = JTS.transform(geom, transform);
      } catch (MismatchedDimensionException e) {

        throw new IOException(e);
      } catch (TransformException e) {

        throw new IOException(e);
      }

      sfb.add(geom);

      SimpleFeature f = sfb.buildFeature(iri.toString());

      sfc.add(f);
    }

    if (!(type.getNs().equals(requestResponse.getFeatureIri().getNs())
        && type.getLocalPart().equals(requestResponse.getFeatureIri().getLocalPart()))) {
      log.debug(
          "[fe] type mismatch for Transport regd "
              + requestResponse.getFeatureIri()
              + " vs added "
              + type
              + " -> properties discarded");
      return;
    }

    if (selectedProperties != null && selectedProperties.size() > 0) {
      ArrayList<Object> props = new ArrayList<Object>(selectedProperties.size());
      for (String field : selectedProperties) {
        props.add(null);
      }
      props.set(0, iri.toString());
      for (Pair<Resource, ?> pair : simpleProperties) {
        Integer keyIndex = selectedPropertiesIndex.get(pair.getKey());
        if (keyIndex == null) {
          /*
           * log.debug("KEY INDEX FOR " + pair.getKey() +
           * " not found");
           */
          continue;
        }
        props.set(keyIndex, pair.getValue());
      }

      list.add(props);
    }
  }
  /* (non-Javadoc)
   * @see forge.control.home.IControlSubmenu#update()
   */
  @SuppressWarnings("serial")
  @Override
  public void initialize() {

    this.view = VSubmenuPreferences.SINGLETON_INSTANCE;
    this.prefs = FModel.getPreferences();

    // This updates variable right now and is not standard
    view.getCbDevMode()
        .addItemListener(
            new ItemListener() {
              @Override
              public void itemStateChanged(final ItemEvent arg0) {
                if (updating) {
                  return;
                }

                final boolean toggle = view.getCbDevMode().isSelected();
                prefs.setPref(FPref.DEV_MODE_ENABLED, String.valueOf(toggle));
                ForgePreferences.DEV_MODE = toggle;
                prefs.save();
              }
            });

    // This updates background track immediately and is not standard
    view.getCbEnableMusic()
        .addItemListener(
            new ItemListener() {
              @Override
              public void itemStateChanged(final ItemEvent arg0) {
                if (updating) {
                  return;
                }

                final boolean toggle = view.getCbEnableMusic().isSelected();
                prefs.setPref(FPref.UI_ENABLE_MUSIC, String.valueOf(toggle));
                prefs.save();
                SoundSystem.instance.changeBackgroundTrack();
              }
            });

    lstControls.clear(); // just in case
    lstControls.add(Pair.of(view.getCbAnte(), FPref.UI_ANTE));
    lstControls.add(Pair.of(view.getCbAnteMatchRarity(), FPref.UI_ANTE_MATCH_RARITY));
    lstControls.add(Pair.of(view.getCbManaBurn(), FPref.UI_MANABURN));
    lstControls.add(Pair.of(view.getCbScaleLarger(), FPref.UI_SCALE_LARGER));
    lstControls.add(Pair.of(view.getCbLargeCardViewers(), FPref.UI_LARGE_CARD_VIEWERS));
    lstControls.add(Pair.of(view.getCbRandomArtInPools(), FPref.UI_RANDOM_ART_IN_POOLS));
    lstControls.add(Pair.of(view.getCbEnforceDeckLegality(), FPref.ENFORCE_DECK_LEGALITY));
    lstControls.add(Pair.of(view.getCbCloneImgSource(), FPref.UI_CLONE_MODE_SOURCE));
    lstControls.add(Pair.of(view.getCbRemoveSmall(), FPref.DECKGEN_NOSMALL));
    lstControls.add(Pair.of(view.getCbRemoveArtifacts(), FPref.DECKGEN_ARTIFACTS));
    lstControls.add(Pair.of(view.getCbSingletons(), FPref.DECKGEN_SINGLETONS));
    lstControls.add(Pair.of(view.getCbEnableAICheats(), FPref.UI_ENABLE_AI_CHEATS));
    lstControls.add(Pair.of(view.getCbDisplayFoil(), FPref.UI_OVERLAY_FOIL_EFFECT));
    lstControls.add(Pair.of(view.getCbRandomFoil(), FPref.UI_RANDOM_FOIL));
    lstControls.add(Pair.of(view.getCbEnableSounds(), FPref.UI_ENABLE_SOUNDS));
    lstControls.add(Pair.of(view.getCbAltSoundSystem(), FPref.UI_ALT_SOUND_SYSTEM));
    lstControls.add(Pair.of(view.getCbUiForTouchScreen(), FPref.UI_FOR_TOUCHSCREN));
    lstControls.add(Pair.of(view.getCbCompactMainMenu(), FPref.UI_COMPACT_MAIN_MENU));
    lstControls.add(Pair.of(view.getCbPromptFreeBlocks(), FPref.MATCHPREF_PROMPT_FREE_BLOCKS));
    lstControls.add(Pair.of(view.getCbPauseWhileMinimized(), FPref.UI_PAUSE_WHILE_MINIMIZED));
    lstControls.add(Pair.of(view.getCbWorkshopSyntax(), FPref.DEV_WORKSHOP_SYNTAX));

    lstControls.add(Pair.of(view.getCbCompactPrompt(), FPref.UI_COMPACT_PROMPT));
    lstControls.add(Pair.of(view.getCbHideReminderText(), FPref.UI_HIDE_REMINDER_TEXT));
    lstControls.add(Pair.of(view.getCbOpenPacksIndiv(), FPref.UI_OPEN_PACKS_INDIV));
    lstControls.add(Pair.of(view.getCbTokensInSeparateRow(), FPref.UI_TOKENS_IN_SEPARATE_ROW));
    lstControls.add(Pair.of(view.getCbStackCreatures(), FPref.UI_STACK_CREATURES));
    lstControls.add(Pair.of(view.getCbManaLostPrompt(), FPref.UI_MANA_LOST_PROMPT));

    lstControls.add(
        Pair.of(view.getCbFilterLandsByColorId(), FPref.UI_FILTER_LANDS_BY_COLOR_IDENTITY));

    for (final Pair<JCheckBox, FPref> kv : lstControls) {
      kv.getKey()
          .addItemListener(
              new ItemListener() {
                @Override
                public void itemStateChanged(final ItemEvent arg0) {
                  if (updating) {
                    return;
                  }

                  prefs.setPref(kv.getValue(), String.valueOf(kv.getKey().isSelected()));
                  prefs.save();
                }
              });
    }

    view.getBtnReset()
        .setCommand(
            new UiCommand() {
              @Override
              public void run() {
                CSubmenuPreferences.this.resetForgeSettingsToDefault();
              }
            });

    view.getBtnDeleteEditorUI()
        .setCommand(
            new UiCommand() {
              @Override
              public void run() {
                CSubmenuPreferences.this.resetDeckEditorLayout();
              }
            });

    view.getBtnDeleteWorkshopUI()
        .setCommand(
            new UiCommand() {
              @Override
              public void run() {
                CSubmenuPreferences.this.resetWorkshopLayout();
              }
            });

    view.getBtnDeleteMatchUI()
        .setCommand(
            new UiCommand() {
              @Override
              public void run() {
                CSubmenuPreferences.this.resetMatchScreenLayout();
              }
            });

    view.getBtnUserProfileUI()
        .setCommand(
            new UiCommand() {
              @Override
              public void run() {
                CSubmenuPreferences.this.openUserProfileDirectory();
              }
            });

    view.getBtnContentDirectoryUI()
        .setCommand(
            new UiCommand() {
              @Override
              public void run() {
                CSubmenuPreferences.this.openContentDirectory();
              }
            });

    initializeGameLogVerbosityComboBox();
    initializeCloseActionComboBox();
    initializeAiProfilesComboBox();
    initializeColorIdentityCombobox();
    initializePlayerNameButton();
  }