コード例 #1
0
ファイル: ListArea.java プロジェクト: luwrain/luwrain
 protected boolean onBeginListeningQuery(BeginListeningQuery query) {
   NullCheck.notNull(query, "query");
   final int index = selectedIndex();
   if (index < 0) return false;
   final int count = model.getItemCount();
   if (index >= count) return false;
   final Object current = model.getItem(index);
   final String text =
       appearance
           .getScreenAppearance(current, NONE_APPEARANCE_FLAGS)
           .substring(hotPointX, appearance.getObservableRightBound(current));
   //	Log.debug("listen", appearance.getScreenAppearance(current, NONE_APPEARANCE_FLAGS));
   //	Log.debug("listen", "" + hotPointX);
   if (text.isEmpty() && index + 1 >= count) return false;
   if (index + 1 < count) {
     final Object next = model.getItem(index + 1);
     query.answer(
         new BeginListeningQuery.Answer(
             text, new ListeningInfo(index + 1, appearance.getObservableLeftBound(next))));
   } else
     query.answer(
         new BeginListeningQuery.Answer(
             text, new ListeningInfo(index, appearance.getObservableRightBound(current))));
   return true;
 }
コード例 #2
0
 /** "dirty" reifications - those with conflicting quadlets - should fail. */
 public void testDirtyReification() {
   Resource R = model.createResource(aURI);
   model.add(R, RDF.type, RDF.Statement);
   model.add(R, RDF.subject, S);
   model.add(R, RDF.subject, P);
   testDoesNotReify("boo", R);
 }
コード例 #3
0
 /**
  * Leo Bard spotted a problem whereby removing a reified statement from a model with style
  * Standard didn't leave the model empty. Here's a test for it.
  */
 public void testLeosBug() {
   Model A = getModel();
   Statement st = statement(A, "pigs fly south");
   ReifiedStatement rst = st.createReifiedStatement("eh:pointer");
   A.removeReification(rst);
   assertIsoModels(ModelFactory.createDefaultModel(), A);
 }
コード例 #4
0
ファイル: Human.java プロジェクト: WheezePuppet/poorHouse
 /*Execute each of the agent's yearly actions in turn*/
 public void step(SimState state) {
   if (Model.instance().generateLifeProb() == 101) {
     mode = LifeStage.DYING;
   }
   // earn
   if (mode == LifeStage.EARNING) {
     this.earnIncome();
     mode = LifeStage.TRADING;
     Model.instance().schedule.scheduleOnceIn(.1, this);
     // trade
   } else if (mode == LifeStage.TRADING) {
     // this.tradeWithRandomAgents();
     this.checkThreeProducers();
     mode = LifeStage.CONSUMING;
     Model.instance().schedule.scheduleOnceIn(.1, this);
     // consume
   } else if (mode == LifeStage.CONSUMING) {
     this.consume();
     // System.out.printf("food price: %f, id: %d, Make: %d\n",expPrice[1],myId,producedCommodity);
     // mode = LifeStage.BIRTHING;
     mode = LifeStage.EARNING;
     Model.instance().schedule.scheduleOnceIn(.8, this);
     age++;
     // child
   } /*else if(mode == LifeStage.BIRTHING){
        this.considerHavingAChild();
        mode = LifeStage.DYING;
        Model.instance().schedule.scheduleOnceIn(.1,this);
     //death
     }*/ else if (mode == LifeStage.DYING) {
     this.considerDeath();
     // mode = LifeStage.EARNING;
   }
 }
コード例 #5
0
ファイル: PrologBackend.java プロジェクト: bungaca/abstools
 // This is the constructor used from runFromShell
 public PrologBackend(String[] args) throws Exception {
   // This parses the args and the ABS program producing the AST whose root is model
   model = parse(args);
   if (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors())
     printParserErrorAndExit();
   initOutStreamEtc();
 }
コード例 #6
0
ファイル: ModelTests.java プロジェクト: gaieepo/HubTurbo
  /**
   * Tests that {@code editIssueState} finds issue with the right id and successfully modify the
   * issue's labels
   */
  @Test
  public void editIssueState_successful() {
    String repoId = "testowner/testrepo";
    Optional<TurboIssue> result;

    TurboIssue issue1 = LogicTests.createOpenIssue();
    TurboIssue issue2 = LogicTests.createClosedIssue();
    List<TurboIssue> issues = Arrays.asList(issue2, issue1);
    Model model =
        new Model(
            repoId,
            issues,
            new ArrayList<TurboLabel>(),
            new ArrayList<TurboMilestone>(),
            new ArrayList<TurboUser>());

    result = model.editIssueState(issue1.getId(), false);
    assertEquals(issue1.getId(), result.get().getId());
    assertEquals(false, result.get().isOpen());

    result = model.editIssueState(issue2.getId(), true);
    assertEquals(issue2.getId(), result.get().getId());
    assertEquals(true, result.get().isOpen());

    result = model.editIssueState(issue2.getId(), true);
    assertEquals(issue2.getId(), result.get().getId());
    assertEquals(true, result.get().isOpen());
  }
コード例 #7
0
  /**
   * Query SPARQL endpoint with a SELECT query
   *
   * @param qExec QueryExecution encapsulating the query
   * @return model retrieved by querying the endpoint
   */
  private Model getSelectModel(QueryExecution qExec) {
    Model model = ModelFactory.createDefaultModel();
    Graph graph = model.getGraph();
    ResultSet results = qExec.execSelect();

    while (results.hasNext()) {
      QuerySolution sol = results.next();
      String subject;
      String predicate;
      RDFNode object;

      try {
        subject = sol.getResource("s").toString();
        predicate = sol.getResource("p").toString();
        object = sol.get("o");
      } catch (NoSuchElementException e) {
        logger.error("SELECT query does not return a (?s ?p ?o) Triple");
        continue;
      }

      Node objNode;
      if (object.isLiteral()) {
        Literal obj = object.asLiteral();
        objNode = NodeFactory.createLiteral(obj.getString(), obj.getDatatype());
      } else {
        objNode = NodeFactory.createLiteral(object.toString());
      }

      graph.add(
          new Triple(NodeFactory.createURI(subject), NodeFactory.createURI(predicate), objNode));
    }

    return model;
  }
コード例 #8
0
ファイル: ListArea.java プロジェクト: luwrain/luwrain
 protected boolean onChar(KeyboardEvent event) {
   if (noContent()) return true;
   final int count = model.getItemCount();
   final char c = event.getChar();
   final String beginning;
   if (selected() != null) {
     if (hotPointX >= appearance.getObservableRightBound(selected())) return false;
     final String name = getObservableSubstr(selected());
     final int pos =
         Math.min(hotPointX - appearance.getObservableLeftBound(selected()), name.length());
     if (pos < 0) return false;
     beginning = name.substring(0, pos);
   } else beginning = "";
   Log.debug("list", "beginning:" + beginning);
   final String mustBegin = beginning + c;
   for (int i = 0; i < count; ++i) {
     Log.debug("list", "checking:" + i);
     final String name = getObservableSubstr(model.getItem(i));
     Log.debug("list", "name:" + name);
     if (!name.startsWith(mustBegin)) continue;
     hotPointY = getLineIndexByItemIndex(i);
     Log.debug("list", "hotPointY:" + hotPointY);
     ++hotPointX;
     appearance.announceItem(model.getItem(hotPointY), NONE_APPEARANCE_FLAGS);
     environment.onAreaNewHotPoint(this);
     return true;
   }
   return false;
 }
コード例 #9
0
 /**
  * Determine whether the given property is recognized and treated specially by this reasoner. This
  * is a convenience packaging of a special case of getCapabilities.
  *
  * @param property the property which we want to ask the reasoner about, given as a Node since
  *     this is part of the SPI rather than API
  * @return true if the given property is handled specially by the reasoner.
  */
 @Override
 public boolean supportsProperty(Property property) {
   if (factory == null) return false;
   Model caps = factory.getCapabilities();
   Resource root = caps.getResource(factory.getURI());
   return caps.contains(root, ReasonerVocabulary.supportsP, property);
 }
コード例 #10
0
ファイル: ListArea.java プロジェクト: luwrain/luwrain
 @Override
 public String getLine(int index) {
   if (isEmpty()) return index == 0 ? noContentStr() : "";
   final int itemIndex = getItemIndexOnLine(index);
   if (itemIndex < 0 || itemIndex >= model.getItemCount()) return "";
   final Object res = model.getItem(itemIndex);
   return res != null ? appearance.getScreenAppearance(res, NONE_APPEARANCE_FLAGS) : "";
 }
コード例 #11
0
 public void testRemoveReificationWorks() {
   Statement st = SPO;
   Model m = model;
   m.createReifiedStatement(aURI, st);
   assertTrue("st is now reified", st.isReified());
   m.removeAllReifications(st);
   assertFalse("st is no longer reified", st.isReified());
 }
コード例 #12
0
  /**
   * Index all the resources in a Jena Model to ES
   *
   * @param model the model to index
   * @param bulkRequest a BulkRequestBuilder
   * @param getPropLabel if set to true all URI property values will be indexed as their label. The
   *     label is taken as the value of one of the properties set in {@link #uriDescriptionList}.
   */
  private void addModelToES(Model model, BulkRequestBuilder bulkRequest, boolean getPropLabel) {
    long startTime = System.currentTimeMillis();
    long bulkLength = 0;
    HashSet<Property> properties = new HashSet<Property>();

    StmtIterator it = model.listStatements();
    while (it.hasNext()) {
      Statement st = it.nextStatement();
      Property prop = st.getPredicate();
      String property = prop.toString();

      if (rdfPropList.isEmpty()
          || (isWhitePropList && rdfPropList.contains(property))
          || (!isWhitePropList && !rdfPropList.contains(property))
          || (normalizeProp.containsKey(property))) {
        properties.add(prop);
      }
    }

    ResIterator resIt = model.listSubjects();

    while (resIt.hasNext()) {
      Resource rs = resIt.nextResource();
      Map<String, ArrayList<String>> jsonMap = getJsonMap(rs, properties, model, getPropLabel);

      bulkRequest.add(
          client.prepareIndex(indexName, typeName, rs.toString()).setSource(mapToString(jsonMap)));
      bulkLength++;

      // We want to execute the bulk for every  DEFAULT_BULK_SIZE requests
      if (bulkLength % EEASettings.DEFAULT_BULK_SIZE == 0) {
        BulkResponse bulkResponse = bulkRequest.execute().actionGet();
        // After executing, flush the BulkRequestBuilder.
        bulkRequest = client.prepareBulk();

        if (bulkResponse.hasFailures()) {
          processBulkResponseFailure(bulkResponse);
        }
      }
    }

    // Execute remaining requests
    if (bulkRequest.numberOfActions() > 0) {
      BulkResponse response = bulkRequest.execute().actionGet();
      // Handle failure by iterating through each bulk response item
      if (response.hasFailures()) {
        processBulkResponseFailure(response);
      }
    }

    // Show time taken to index the documents
    logger.info(
        "Indexed {} documents on {}/{} in {} seconds",
        bulkLength,
        indexName,
        typeName,
        (System.currentTimeMillis() - startTime) / 1000.0);
  }
コード例 #13
0
ファイル: ProxyAuto.java プロジェクト: kikikimi/kbookweb
 // prints to console based on if the model name is found
 public void printAuto(String modelName) {
   _autoModel = _autoModelGroup.get(modelName);
   if (_autoModel != null) {
     // using toStringWChoices to show optionChoice is functional
     System.out.println(_autoModel.toStringWChoices(true));
     System.out.print("Price with selected options(may be defaults):");
     System.out.println(_autoModel.getTotalPrice());
   } else System.out.print("Model name" + modelName + "not found");
 }
コード例 #14
0
 /**
  * Add to <code>toAdd</code> all the superclass statements needed to note that any indirect
  * subclass of <code>X = parents.item</code> has as superclass all the classes between it and X
  * and all the remaining elements of <code>parents</code>.
  */
 private static void addSuperClasses(Model m, LinkedSeq parents, Model toAdd) {
   Resource type = parents.item;
   for (StmtIterator it = m.listStatements(null, RDFS.subClassOf, type); it.hasNext(); ) {
     Resource t = it.nextStatement().getSubject();
     for (LinkedSeq scan = parents.rest; scan != null; scan = scan.rest)
       toAdd.add(t, RDFS.subClassOf, scan.item);
     addSuperClasses(m, parents.push(t), toAdd);
   }
 }
コード例 #15
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  public static Resource getSubject(Model r, Resource predicate, RDFNode object)
      throws ModelException {

    Model m = r.find(null, predicate, object);
    if (m == null || m.size() == 0) return null;
    //    if(m.size() > 1)
    //      throw new RuntimeException("Model contains more than one triple");
    return ((Statement) m.elements().nextElement()).subject();
  }
コード例 #16
0
ファイル: RenderState.java プロジェクト: grafov/tribaltrouble
 public final void transform(ElementRenderState render_state) {
   Model model = render_state.model;
   RenderTools.translateAndRotate(
       model.getPositionX(),
       model.getPositionY(),
       render_state.f,
       model.getDirectionX(),
       model.getDirectionY());
 }
コード例 #17
0
ファイル: QueryTest.java プロジェクト: hdadler/sensetrace-src
 void printFailedModelTest(Query query, Model expected, Model results) {
   PrintWriter out = FileUtils.asPrintWriterUTF8(System.out);
   out.println("=======================================");
   out.println("Failure: " + description());
   results.write(out, "TTL");
   out.println("---------------------------------------");
   expected.write(out, "TTL");
   out.println();
 }
コード例 #18
0
 public void testBulkByModelReifying(boolean suppress) {
   Model m = modelWithStatements(ReificationStyle.Minimal, "a P b");
   addReification(m, "x", "S P O");
   addReification(m, "a", "x R y");
   Model target = modelWithStatements(ReificationStyle.Minimal, "");
   target.add(m, suppress);
   target.setNsPrefixes(PrefixMapping.Standard);
   assertIsoModels((suppress ? modelWithStatements("a P b") : m), target);
 }
コード例 #19
0
 public void testStatementListReifiedStatements() {
   Statement st = SPO;
   Model m = model;
   assertEquals(
       "it's not there yet", empty, GraphTestBase.iteratorToSet(st.listReifiedStatements()));
   ReifiedStatement rs = m.createReifiedStatement(aURI, st);
   Set justRS = arrayToSet(new Object[] {rs});
   m.add(rs, P, O);
   assertEquals("it's here now", justRS, GraphTestBase.iteratorToSet(st.listReifiedStatements()));
 }
コード例 #20
0
ファイル: Human.java プロジェクト: WheezePuppet/poorHouse
 /*Probabilistically determine whether an agent will have a child
 and add a new agent to the schedule if so*/
 public void considerHavingAChild() {
   int prob = Model.instance().generateChild();
   if (age >= 20 && age < 35) {
     if (prob > 90) {
       Human newchild = new Human(this);
       Model.instance().schedule.scheduleOnceIn(.6, newchild);
       Model.instance().incrementPopulation();
     }
   }
 }
コード例 #21
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  public static RDFNode getObject(Model r, Resource subject, Resource predicate)
      throws ModelException {

    Model m = r.find(subject, predicate, null);
    if (m == null || m.size() == 0) return null;
    //    if(m.size() > 1)
    //      throw new RuntimeException("Model contains more than one triple");
    // FIXME: we do not check whether it is a resource or literal
    return ((Statement) m.elements().nextElement()).object();
  }
コード例 #22
0
ファイル: ProxyAuto.java プロジェクト: kikikimi/kbookweb
 public void updateOptionSetName(String modelName, String optionSetName, String newName) {
   int setIndex;
   _autoModel = _autoModelGroup.get(modelName);
   if (_autoModel != null) {
     setIndex = _autoModel.findOptionSetIndex(optionSetName);
     if (setIndex != -1) {
       _autoModel.updateOptionSetName(setIndex, newName);
     }
   }
 }
コード例 #23
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  /** Collects the triples of a model into an array. */
  public static Statement[] getStatementArray(Model m) throws ModelException {

    Statement[] v = new Statement[m.size()];
    int i = 0;
    for (Enumeration en = m.elements(); en.hasMoreElements(); ) {

      Statement t = (Statement) en.nextElement();
      v[i++] = t;
    }
    return v;
  }
コード例 #24
0
ファイル: ProxyAuto.java プロジェクト: kikikimi/kbookweb
 // optionName goes with optionset, optVal is the String property in an option.
 public void updateOptionPrice(
     String modelName, String optionName, String optVal, float newprice) {
   int setIndex;
   _autoModel = _autoModelGroup.get(modelName);
   if (_autoModel != null) {
     setIndex = _autoModel.findOptionSetIndex(optionName);
     if (setIndex != -1) {
       _autoModel.updateOptionPrice(setIndex, optVal, newprice);
     }
   }
 }
コード例 #25
0
 public void testRR() {
   Statement st = SPO;
   Model m = model;
   ReifiedStatement rs1 = m.createReifiedStatement(aURI, st);
   ReifiedStatement rs2 = m.createReifiedStatement(anotherURI, st);
   m.removeReification(rs1);
   testNotReifying(m, aURI);
   assertTrue("st is still reified", st.isReified());
   m.removeReification(rs2);
   assertFalse("st should no longer be reified", st.isReified());
 }
コード例 #26
0
ファイル: RDFUtil.java プロジェクト: mepcotterell/cs8470-ads
  // FIXME: use digest instead of size
  static void getReachable(Resource r, Model m, Model result) throws ModelException {

    int oldSize = result.size();
    Model directlyReachable = m.find(r, null, null);
    SetOperations.unite(result, directlyReachable);
    if (result.size() == oldSize) return;
    for (Enumeration en = directlyReachable.elements(); en.hasMoreElements(); ) {
      Statement t = (Statement) en.nextElement();
      if (t.object() instanceof Resource) getReachable((Resource) t.object(), m, result);
    }
  }
コード例 #27
0
 protected static void addDomainTypes(Model result, Model schema) {
   for (StmtIterator it = schema.listStatements(ANY, RDFS.domain, ANY); it.hasNext(); ) {
     Statement s = it.nextStatement();
     Property property = s.getSubject().as(Property.class);
     RDFNode type = s.getObject();
     for (StmtIterator x = result.listStatements(ANY, property, ANY); x.hasNext(); ) {
       Statement t = x.nextStatement();
       result.add(t.getSubject(), RDF.type, type);
     }
   }
 }
コード例 #28
0
ファイル: ProxyAuto.java プロジェクト: kikikimi/kbookweb
 // optionName goes with optionset, optVal is the String property in an option.
 public void updateOptionValue(
     String modelName, String optionName, String oldOptVal, String newOptVal) {
   int setIndex;
   _autoModel = _autoModelGroup.get(modelName);
   if (_autoModel != null) {
     setIndex = _autoModel.findOptionSetIndex(optionName);
     if (setIndex != -1) {
       if (_autoModel.updateOptionName(setIndex, oldOptVal, newOptVal))
         System.out.println(newOptVal + " set!");
     }
   }
 }
コード例 #29
0
  @Test
  public void testTermbindsIncludesMetaproperties() throws URISyntaxException {
    Integer totalResults = null;
    Resource thisMetaPage = createMetadata(false, totalResults);

    for (Property p : expectedTermboundProperties) {
      Model model = thisMetaPage.getModel();
      if (!model.contains(null, API.property, p)) {
        fail("term bindings should include " + model.shortForm(p.getURI()));
      }
    }
  }
コード例 #30
0
 /** Run a single test of any sort, return true if the test succeeds. */
 public boolean doRunTest(Resource test) throws IOException {
   if (test.hasProperty(RDF.type, OWLTest.PositiveEntailmentTest)
       || test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest)
       || test.hasProperty(RDF.type, OWLTest.OWLforOWLTest)
       || test.hasProperty(RDF.type, OWLTest.ImportEntailmentTest)
       || test.hasProperty(RDF.type, OWLTest.TrueTest)) {
     // Entailment tests
     boolean processImports = test.hasProperty(RDF.type, OWLTest.ImportEntailmentTest);
     Model premises = getDoc(test, RDFTest.premiseDocument, processImports);
     Model conclusions = getDoc(test, RDFTest.conclusionDocument);
     comprehensionAxioms(premises, conclusions);
     long t1 = System.currentTimeMillis();
     InfGraph graph = reasoner.bind(premises.getGraph());
     if (printProfile) {
       ((FBRuleInfGraph) graph).resetLPProfile(true);
     }
     Model result = ModelFactory.createModelForGraph(graph);
     boolean correct = WGReasonerTester.testConclusions(conclusions.getGraph(), result.getGraph());
     long t2 = System.currentTimeMillis();
     lastTestDuration = t2 - t1;
     if (printProfile) {
       ((FBRuleInfGraph) graph).printLPProfile();
     }
     if (test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest)) {
       correct = !correct;
     }
     return correct;
   } else if (test.hasProperty(RDF.type, OWLTest.InconsistencyTest)) {
     //            System.out.println("Starting: " + test);
     Model input = getDoc(test, RDFTest.inputDocument);
     long t1 = System.currentTimeMillis();
     InfGraph graph = reasoner.bind(input.getGraph());
     boolean correct = !graph.validate().isValid();
     long t2 = System.currentTimeMillis();
     lastTestDuration = t2 - t1;
     return correct;
   } else if (test.hasProperty(RDF.type, OWLTest.ConsistencyTest)) {
     // Not used normally becase we are not complete enough to prove consistency
     //            System.out.println("Starting: " + test);
     Model input = getDoc(test, RDFTest.inputDocument);
     long t1 = System.currentTimeMillis();
     InfGraph graph = reasoner.bind(input.getGraph());
     boolean correct = graph.validate().isValid();
     long t2 = System.currentTimeMillis();
     lastTestDuration = t2 - t1;
     return correct;
   } else {
     for (StmtIterator i = test.listProperties(RDF.type); i.hasNext(); ) {
       System.out.println("Test type = " + i.nextStatement().getObject());
     }
     throw new ReasonerException("Unknown test type");
   }
 }