public List<Rule> findAllRules() { IntegerElement x, y; ArrayList<Rule> rules = new ArrayList<Rule>(); for (x = (IntegerElement) getMinX(); x.compareTo(getMaxX()) <= 0; x = x.succ()) { for (y = (IntegerElement) getMinY(); y.compareTo(getMaxY()) <= 0; y = y.succ()) { boolean escaped = (!y.isZero() && get(x, y.pred()).getChar() != ' '); if (escaped) continue; if (get(x, y).getChar() == '(') { // System.out.println("Found a rule start at " + x + ", " + y); IntegerElement x2 = x; CharacterElement g = get(x2, y); while (g.getChar() != ')' && x2.compareTo(getMaxX()) <= 0) { x2 = x2.succ(); g = get(x2, y); } if (g.getChar() != ')') continue; // System.out.println("Found a rule from " + x + "," + y + " to " + x2); CharacterElement w = get(x2.pred(), y); if (w.getChar() == ' ') w = null; Rule r = new Rule(this, x.succ(), y.succ(), (x2.subtract(x)).pred(), w); rules.add(r); } } } return rules; }
/* * We assume a match was made at the given position. */ public void applyRule(Rule r, Position p) { IntegerElement i, j; CharacterElement wildcard = r.getWildcard(); // System.out.printf("applying at %s: %s", p.toString(), r.dump()); /* Note that r.getHeight() == width/2 ... */ for (i = IntegerElement.ZERO; i.compareTo(r.getHeight()) < 0; i = i.succ()) { for (j = IntegerElement.ZERO; j.compareTo(r.getHeight()) < 0; j = j.succ()) { CharacterElement replacement = r.get(i.add(r.getHeight()), j); IntegerElement destX = p.getX().add(i); IntegerElement destY = p.getY().add(j); // System.out.printf("(%s,%s): [%s] '%s' -> (%s,%s)\n", i, j, wildcard, // replacement.getChar(), destX, destY); if (wildcard == null || wildcard.getChar() != replacement.getChar()) { set(destX, destY, replacement); } } } }
public static void addStateDataToBones(RootElement root, AmcData amc_data) throws Exception { logger.debug("AmcMapper.addStateDataToBones(): Entering method."); logger.info("AmcMapper.addStateDataToBones(): {} frames to parse.", amc_data.frames.size()); for (int i = 0; i < amc_data.frames.size(); i++) { logger.info("AmcMapper.addStateDataToBones(): Adding frame {}.", i + 1); AcclaimFrame frame = amc_data.frames.get(i); for (Entry<String, List<Float>> entry : frame.bone_orientation.entrySet()) { CharacterElement character_element = root.findCharacterElement(entry.getKey()); CharacterElementState new_state = new CharacterElementState(entry.getValue()); logger.info( "AmcMapper.addStateDataToBones(): Add state {} to {}.", new_state.toString(), character_element.getName()); character_element.getStates().add(new_state); } } logger.debug("AmcMapper.addStateDataToBones(): Exiting method."); }
public boolean match(CharacterElement sought, CharacterElement candidate) { if (wildcard != null && sought.getChar() == wildcard.getChar()) { return true; } return candidate.equals(sought); }
public String dumpElement(CharacterElement e) { return e.getName(); }