Ejemplo n.º 1
0
 @Override
 public BlockDesign setQuad(Quad quad) {
   return setVertex(quad.getVertex(0))
       .setVertex(quad.getVertex(1))
       .setVertex(quad.getVertex(2))
       .setVertex(quad.getVertex(3));
 }
 private void delete$(Quad quad) {
   super.delete(quad);
   record(
       QuadAction.DELETE,
       quad.getGraph(),
       quad.getSubject(),
       quad.getPredicate(),
       quad.getObject());
 }
Ejemplo n.º 3
0
  @Override
  public final void drawTexture(
      final GL gl,
      Texture texture,
      final float x,
      float y,
      float z,
      int texturex,
      int texturey,
      int width,
      int height,
      float scale) {
    Check.notNull(gl, "GL cannot be null");
    Check.notNull(texture, "Texture cannot be null");

    final TextureCoords coords =
        texture.getSubImageTexCoords(texturex, texturey, texturex + width, texturey + height);

    // Compute position and size
    quad.xl = x;
    quad.xr = quad.xl + (scale * width);
    quad.yb = y;
    quad.yt = quad.yb + (scale * height);
    quad.z = z;
    quad.sl = coords.left();
    quad.sr = coords.right();
    quad.tb = coords.bottom();
    quad.tt = coords.top();

    // Draw quad
    pipeline.addQuad(gl, quad);
  }
Ejemplo n.º 4
0
  /** Generate a sentence that includes (if possible) the specified word. */
  public String getSentence(String word) {
    LinkedList parts = new LinkedList();

    Quad[] quads;
    if (words.containsKey(word)) {
      quads = (Quad[]) ((HashSet) words.get(word)).toArray(new Quad[0]);
    } else {
      quads = (Quad[]) this.quads.keySet().toArray(new Quad[0]);
    }

    if (quads.length == 0) {
      return "";
    }

    Quad middleQuad = quads[rand.nextInt(quads.length)];
    Quad quad = middleQuad;

    for (int i = 0; i < 4; i++) {
      parts.add(quad.getToken(i));
    }

    while (quad.canEnd() == false) {
      String[] nextTokens = (String[]) ((HashSet) next.get(quad)).toArray(new String[0]);
      String nextToken = nextTokens[rand.nextInt(nextTokens.length)];
      quad =
          (Quad)
              this.quads.get(
                  new Quad(quad.getToken(1), quad.getToken(2), quad.getToken(3), nextToken));
      parts.add(nextToken);
    }

    quad = middleQuad;
    while (quad.canStart() == false) {
      String[] previousTokens = (String[]) ((HashSet) previous.get(quad)).toArray(new String[0]);
      String previousToken = previousTokens[rand.nextInt(previousTokens.length)];
      quad =
          (Quad)
              this.quads.get(
                  new Quad(previousToken, quad.getToken(0), quad.getToken(1), quad.getToken(2)));
      parts.addFirst(previousToken);
    }

    StringBuffer sentence = new StringBuffer();
    Iterator it = parts.iterator();
    while (it.hasNext()) {
      String token = (String) it.next();
      sentence.append(token);
    }

    return sentence.toString();
  }
 @Override
 public void delete(Quad quad) {
   if (CheckFirst && !contains(quad)) {
     if (RecordNoAction)
       record(
           QuadAction.NO_DELETE,
           quad.getGraph(),
           quad.getSubject(),
           quad.getPredicate(),
           quad.getObject());
     return;
   }
   delete$(quad);
 }
 @Override
 public void add(Quad quad) {
   if (CheckFirst && contains(quad)) {
     if (RecordNoAction)
       record(
           QuadAction.NO_ADD,
           quad.getGraph(),
           quad.getSubject(),
           quad.getPredicate(),
           quad.getObject());
     return;
   }
   add$(quad);
 }
Ejemplo n.º 7
0
  @Test
  public void testQuad() {
    Quad<String, String, String, String> o1 = new Quad<String, String, String, String>();

    o1.setEast("east");
    o1.setSouth("south");
    o1.setWest("west");
    o1.setNorth("north");

    Quad<String, String, String, String> o2 =
        new Quad<String, String, String, String>("east", "south", "west", "north");

    Assert.assertEquals(o1, o2);
    Assert.assertEquals(o1.hashCode(), o2.hashCode());
    Assert.assertEquals(o1.toString(), o2.toString());
  }
Ejemplo n.º 8
0
 public LiquidModel(Texture texture, int textureIds[], boolean top, int subWidth, int subHeight) {
   super(texture, textureIds, subWidth, subHeight);
   this.setUseCulling(false);
   this.setCollisionBox(null);
   this.setSelectionBox(null);
   if (top) {
     for (Quad quad : this.getQuads()) {
       for (int vert = 0; vert < quad.getVertices().size(); vert++) {
         Vertex v = quad.getVertices().get(vert);
         if (v.getY() == 1) {
           quad.setVertex(vert, new Vertex(v.getX(), 0.95f, v.getZ()));
         }
       }
     }
   }
 }
Ejemplo n.º 9
0
 /**
  * Choose a graph from a DatasetGraph. If it's the union, provide a union graph (not always the
  * best way to deal with union).
  *
  * @param dataset
  * @param graphNode
  * @return Graph
  */
 protected static Graph chooseGraph(DatasetGraph dataset, Node graphNode) {
   if (graphNode == null) return dataset.getDefaultGraph();
   else if (Var.isVar(graphNode))
     throw new NotImplemented("Choosing a graph OpExecutorStage.executeBlockFilter[Variable]");
   else if (graphNode == Node.ANY)
     throw new NotImplemented("OpExecutorMain.executeBlockFilter[Node.ANY]");
   else if (Quad.isUnionGraph(graphNode)) {
     // TODO Check this!  Work needed here to consolidate union graph handling.
     List<Node> graphs = Iter.toList(dataset.listGraphNodes());
     return new GraphUnionRead(dataset, graphs);
   } else return dataset.getGraph(graphNode);
 }
Ejemplo n.º 10
0
  private ListMultimap<String, TextHit> query(
      Node property, String queryString, int limit, ExecutionContext execCxt) {
    // use the graph information in the text index if possible
    if (textIndex.getDocDef().getGraphField() != null
        && execCxt.getActiveGraph() instanceof GraphView) {
      GraphView activeGraph = (GraphView) execCxt.getActiveGraph();
      if (!Quad.isUnionGraph(activeGraph.getGraphName())) {
        String uri =
            activeGraph.getGraphName() != null
                ? TextQueryFuncs.graphNodeToString(activeGraph.getGraphName())
                : Quad.defaultGraphNodeGenerated.getURI();
        String escaped = QueryParserBase.escape(uri);
        String qs2 = textIndex.getDocDef().getGraphField() + ":" + escaped;
        queryString = "(" + queryString + ") AND " + qs2;
      }
    }

    // for language-based search extension
    if (textIndex.getDocDef().getLangField() != null) {
      String field = textIndex.getDocDef().getLangField();
      if (langArg != null) {
        String qs2 = !"none".equals(langArg) ? field + ":" + langArg : "-" + field + ":*";
        queryString = "(" + queryString + ") AND " + qs2;
      }
    }

    Explain.explain(execCxt.getContext(), "Text query: " + queryString);
    if (log.isDebugEnabled()) log.debug("Text query: {} ({})", queryString, limit);

    String cacheKey = limit + " " + property + " " + queryString;
    Cache<String, ListMultimap<String, TextHit>> queryCache =
        (Cache<String, ListMultimap<String, TextHit>>) execCxt.getContext().get(cacheSymbol);
    if (queryCache == null) {
        /* doesn't yet exist, need to create it */
      queryCache = CacheFactory.createCache(CACHE_SIZE);
      execCxt.getContext().put(cacheSymbol, queryCache);
    }

    final String queryStr = queryString; // final needed for the lambda function
    ListMultimap<String, TextHit> results =
        queryCache.getOrFill(
            cacheKey,
            () -> {
              List<TextHit> resultList = textIndex.query(property, queryStr, limit);
              ListMultimap<String, TextHit> resultMultimap = LinkedListMultimap.create();
              for (TextHit result : resultList) {
                resultMultimap.put(result.getNode().getURI(), result);
              }
              return resultMultimap;
            });
    return results;
  }
 private void add$(Quad quad) {
   super.add(quad);
   record(
       QuadAction.ADD, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject());
 }
Ejemplo n.º 12
0
 public static void addVarsFromQuad(Collection<Var> acc, Quad q) {
   addVar(acc, q.getSubject());
   addVar(acc, q.getPredicate());
   addVar(acc, q.getObject());
   addVar(acc, q.getGraph());
 }
Ejemplo n.º 13
0
  /** Adds a new sentence to the 'brain' */
  public void add(String sentence) {
    sentence = sentence.trim();
    ArrayList parts = new ArrayList();
    char[] chars = sentence.toCharArray();
    int i = 0;
    boolean punctuation = false;
    StringBuffer buffer = new StringBuffer();
    while (i < chars.length) {
      char ch = chars[i];
      if ((WORD_CHARS.indexOf(ch) >= 0) == punctuation) {
        punctuation = !punctuation;
        String token = buffer.toString();
        if (token.length() > 0) {
          parts.add(token);
        }
        buffer = new StringBuffer();
        // i++;
        continue;
      }
      buffer.append(ch);
      i++;
    }
    String lastToken = buffer.toString();
    if (lastToken.length() > 0) {
      parts.add(lastToken);
    }

    if (parts.size() >= 4) {
      for (i = 0; i < parts.size() - 3; i++) {
        // System.out.println("\"" + parts.get(i) + "\"");
        Quad quad =
            new Quad(
                (String) parts.get(i),
                (String) parts.get(i + 1),
                (String) parts.get(i + 2),
                (String) parts.get(i + 3));
        if (quads.containsKey(quad)) {
          quad = (Quad) quads.get(quad);
        } else {
          quads.put(quad, quad);
        }

        if (i == 0) {
          quad.setCanStart(true);
        }
        // else if (i == parts.size() - 4) {
        if (i == parts.size() - 4) {
          quad.setCanEnd(true);
        }

        for (int n = 0; n < 4; n++) {
          String token = (String) parts.get(i + n);
          if (!words.containsKey(token)) {
            words.put(token, new HashSet(1));
          }
          HashSet set = (HashSet) words.get(token);
          set.add(quad);
        }

        if (i > 0) {
          String previousToken = (String) parts.get(i - 1);
          if (!previous.containsKey(quad)) {
            previous.put(quad, new HashSet(1));
          }
          HashSet set = (HashSet) previous.get(quad);
          set.add(previousToken);
        }

        if (i < parts.size() - 4) {
          String nextToken = (String) parts.get(i + 4);
          if (!next.containsKey(quad)) {
            next.put(quad, new HashSet(1));
          }
          HashSet set = (HashSet) next.get(quad);
          set.add(nextToken);
        }
      }
    } else {
      // Didn't learn anything.
    }
  }