Examples of Verb


Examples of ar.com.dgarcia.java_verbs.api.Verb

        return defineVerb(functionName, verbDefinition);
    }

    @Override
    public Verb named(String functionName) {
        Verb verb = verbs.get(functionName);
        if(verb == null){
            throw new VerbException("The requested verb["+functionName+"] does not exists");
        }
        return verb;
    }
View Full Code Here

Examples of ar.com.dgarcia.java_verbs.api.Verb

     * @param functionName The name for the verb
     * @param verbDefinition The new definition
     * @return The existing or created verb
     */
    private Verb defineVerb(String functionName, Lambda verbDefinition) {
        Verb existingVerb = verbs.get(functionName);
        if(existingVerb != null){
            existingVerb.redefine(verbDefinition);
            return existingVerb;
        }
        VerbImpl createdVerb = VerbImpl.create(functionName, verbDefinition);
        verbs.put(functionName, createdVerb);
        return createdVerb;
View Full Code Here

Examples of ar.com.dgarcia.java_verbs.api.Verb

    @Override
    public void define() {

        describe("a piece of behavior", ()->{

            Verb verb = Verbs.in("tests").asFunction("name", () -> "John Smith");

            it("is a function defined in a namespace", () -> {
                String returnedValue = verb.apply();

                assertThat(returnedValue).isEqualTo("John Smith");
            });

            it("that can be used to implement a method", () -> {
                TestObject testObject = new TestObject();

                assertThat(testObject.name()).isEqualTo("John Smith");
            });

        });

        describe("functions can be shared", () -> {

            Verbs.in("tests").asFunction("play", (first, second) -> first + " is playing with " + second);

            it("between types with a common ancestor", () -> {
                Human brother = Human.create("Hansel");
                Human sister = Human.create("Gretel");

                assertThat(brother.playWith(sister)).isEqualTo("Hansel is playing with Gretel");
                assertThat(sister.playWith(brother)).isEqualTo("Gretel is playing with Hansel");
            });

            it("between unrelated types", () -> {
                Cat garfield = Cat.create("Garfield");
                Dog odie = Dog.create("Odie");

                assertThat(garfield.playWith(odie)).isEqualTo("Garfield is playing with Odie");
                assertThat(odie.playWith(garfield)).isEqualTo("Odie is playing with Garfield");
            });

        });

        describe("when sharing among unrelated types", () -> {

            Verbs.in("tests").asFunction("drive", (person, car) -> person + " is driving " + car);

            it("method names can differ to improve expressiveness", () -> {
                Human schummy = Human.create("Schumacher");
                Car fantasticCar = Car.create("KITT");

                assertThat(schummy.drive(fantasticCar)).isEqualTo("Schumacher is driving KITT");
                assertThat(fantasticCar.drivenBy(schummy)).isEqualTo("Schumacher is driving KITT");
            });

        });

        describe("a transfer that involves 3 parties: sender, receiver and the transferred object", () -> {

            Sender planetEarth = Sender.create("Earth");
            Receiver moon = Receiver.create("Moon");
            Spaceship apollo11 = Spaceship.create("Apollo11");

            Verbs.in("tests").asFunction("transfer", (object, origin, destination) -> object + " is transferred from " + origin + " to " + destination);

            it("can be expressed with the sender as the subject", () -> {

                assertThat(planetEarth.sendTo(moon, apollo11)).isEqualTo("Apollo11 is transferred from Earth to Moon");
            });

            it("with the receiver as subject", () -> {

                assertThat(moon.receiveFrom(planetEarth, apollo11)).isEqualTo("Apollo11 is transferred from Earth to Moon");
            });

            it("or the object as the subject", () -> {

                assertThat(apollo11.travelBetween(planetEarth, moon)).isEqualTo("Apollo11 is transferred from Earth to Moon");
            });
        });

        describe("behavior", ()->{

            Verb verb = Verbs.in("tests").asFunction("salute", () -> "Hello");


            it("can be re-defined in runtime", ()->{
                assertThat(verb.<String>apply()).isEqualTo("Hello");

                Verbs.in("tests").asFunction("salute", () -> "Bye");

                assertThat(verb.<String>apply()).isEqualTo("Bye");
            });

        });

    }
View Full Code Here

Examples of ar.com.dgarcia.java_verbs.api.Verb

        context().operation(()-> mock(TestOperation.class));

        describe("a verb with no return value", () -> {

            it("and no argument", () -> {
                Verb verb = Verbs.in("test").asAction("test", () -> context().operation().operationWithNoReturn());

                verb.apply();

                verify(context().operation()).operationWithNoReturn();
            });

            it("1 argument", () -> {
                Verb verb = Verbs.in("test").asAction("test", (first) -> context().operation().operationWithNoReturn(first));

                verb.apply("1");

                verify(context().operation()).operationWithNoReturn("1");
            });

            it("2 arguments", () -> {
                Verb verb = Verbs.in("test").asAction("test", (first, second) -> context().operation().operationWithNoReturn(first, second));

                verb.apply("1", "2");

                verify(context().operation()).operationWithNoReturn("1", "2");
            });

            it("3 arguments", () -> {
                Verb verb = Verbs.in("test").asAction("test", (first, second, third) -> context().operation().operationWithNoReturn(first, second, third));

                verb.apply("1", "2", "3");

                verify(context().operation()).operationWithNoReturn("1", "2", "3");
            });

            it("4 arguments", () -> {
                Verb verb = Verbs.in("test").asAction("test", (first, second, third, fourth, extra) -> context().operation().operationWithNoReturn(first, second, third, fourth));

                verb.apply("1", "2", "3", "4");

                verify(context().operation()).operationWithNoReturn("1", "2", "3", "4");
            });

            it("5 or more arguments", () -> {
                Verb verb = Verbs.in("test").asAction("test", (first, second, third, fourth, extra) -> context().operation().operationWithNoReturn(first, second, third, fourth, extra[0]));

                verb.apply("1", "2", "3", "4", "5");

                verify(context().operation()).operationWithNoReturn("1", "2", "3", "4", "5");
            });

        });

        describe("a verb with return value", ()->{

            it("and no argument", ()->{
                Verb verb = Verbs.in("test").asFunction("test", () -> context().operation().operationWithReturn());

                verb.apply();

                verify(context().operation()).operationWithReturn();
            });

            it("1 argument", ()->{
                Verb verb = Verbs.in("test").asFunction("test", (first) -> context().operation().operationWithReturn(first));

                verb.apply("1");

                verify(context().operation()).operationWithReturn("1");
            });

            it("2 arguments", ()->{
                Verb verb = Verbs.in("test").asFunction("test", (first, second) -> context().operation().operationWithReturn(first, second));

                verb.apply("1", "2");

                verify(context().operation()).operationWithReturn("1","2");
            });

            it("3 arguments", ()->{
                Verb verb = Verbs.in("test").asFunction("test", (first, second, third) -> context().operation().operationWithReturn(first, second, third));

                verb.apply("1", "2", "3");

                verify(context().operation()).operationWithReturn("1","2", "3");
            });

            it("4 arguments", ()->{
                Verb verb = Verbs.in("test").asFunction("test", (first, second, third, fourth, extra) -> context().operation().operationWithReturn(first, second, third, fourth));

                verb.apply("1", "2", "3", "4");

                verify(context().operation()).operationWithReturn("1", "2", "3", "4");
            });

            it("5 or more arguments", ()->{
                Verb verb = Verbs.in("test").asFunction("test", (first, second, third, fourth, extra) -> context().operation().operationWithReturn(first, second, third, fourth, extra[0]));

                verb.apply("1", "2", "3", "4", "5");

                verify(context().operation()).operationWithReturn("1", "2", "3", "4", "5");
            });
        });
View Full Code Here

Examples of net.sf.nlpshell.domain.word.verb.Verb

    SemanticFrame searchFrame = pos.frame();
    String frameString = searchFrame.toFrameString();
    System.out.println("Frame : " + frameString);

    // extract verb
    Verb verb = searchFrame.getVerb();

    // choose lemma
    IndexWord iw = Dictionary.getInstance().lookupIndexWord(
        net.didion.jwnl.data.POS.VERB, verb.text);
    System.out.println("lemma : " + iw.getLemma());
    System.out.println("senses : " + iw.getSenseCount());
    String verbLemma = iw.getLemma();

    // find verb interpretation
    File verbnetDir = new File("verbnet-3.1");
    if (!verbnetDir.exists()) {
      throw new IllegalStateException("Non trovo verbnet : ["
          + verbnetDir.getAbsolutePath() + "]");
    }
    Map<String, Set<VNCLASS>> frameMembers = new LinkedHashMap<String, Set<VNCLASS>>();
    Map<String, Set<VNSUBCLASS>> frameSubclassMembers = new LinkedHashMap<String, Set<VNSUBCLASS>>();
    JAXBContext jaxbContext = JAXBContext.newInstance("vn");
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    FilenameFilter wildcardFileFilter = new WildcardFileFilter("*.xml");
    for (File verbnetFile : verbnetDir.listFiles(wildcardFileFilter)) {
      JAXBElement<VNCLASS> jaxbElement;
      try {
        jaxbElement = unmarshaller.unmarshal(new StreamSource(
            verbnetFile), VNCLASS.class);
      } catch (Exception e) {
        throw new IllegalStateException("Impossibile elaborare : ["
            + verbnetFile.getAbsolutePath() + "]", e);
      }
      VNCLASS vnclass = jaxbElement.getValue();
      for (MEMBER member : vnclass.getMEMBERS().getMEMBER()) {
        if (frameMembers.containsKey(member.getName())) {
          frameMembers.get(member.getName()).add(vnclass);
        } else {
          Set<VNCLASS> classes = new HashSet<VNCLASS>();
          classes.add(vnclass);
          frameMembers.put(member.getName(), classes);
        }
      }
      for (VNSUBCLASS vnsubclass : vnclass.getSUBCLASSES()
          .getVNSUBCLASS()) {
        for (MEMBER member : vnsubclass.getMEMBERS().getMEMBER()) {
          if (frameMembers.containsKey(member.getName())) {
            frameMembers.get(member.getName()).add(vnclass);
          } else {
            Set<VNCLASS> classes = new HashSet<VNCLASS>();
            classes.add(vnclass);
            frameMembers.put(member.getName(), classes);
          }
          if (frameSubclassMembers.containsKey(member.getName())) {
            frameSubclassMembers.get(member.getName()).add(
                vnsubclass);
          } else {
            Set<VNSUBCLASS> classes = new HashSet<VNSUBCLASS>();
            classes.add(vnsubclass);
            frameSubclassMembers.put(member.getName(), classes);
          }
        }
      }
    }

    Set<String> knownPredicates = new HashSet<String>();
    knownPredicates.add("discover");
    Set<VNCLASS> vnclasses = frameMembers.get(verbLemma);
    // Set<VNSUBCLASS> vnSubclasses = frameSubclassMembers.get(verbLemma);
    VerbnetInfo verbnetInfo = chooseFrame(searchFrame, knownPredicates,
        vnclasses);
    int position = 0;
    List<Object> npOrVERBOrADJOrADVOrPREPOrLEX = verbnetInfo.frame
        .getSYNTAX().getNPOrVERBOrADJOrADVOrPREPOrLEX();
    for (final Object object : npOrVERBOrADJOrADVOrPREPOrLEX) {
      if (object instanceof NP) {
        NP np = (NP) object;
        FrameItem frameItem = searchFrame.components.get(position);
        frameItem.pos.thematicRole = ThematicRoles.valueOf(np
            .getValue().toUpperCase());
      }
      if (object instanceof VERB) {
        FrameItem frameItem = searchFrame.components.get(position);
        System.out.println("Verb : " + frameItem.pos.text);
        Verb v = ((Verb) frameItem.pos);
        v.predicate = Predicates.valueOf(verbnetInfo.predicate
            .getValue().toUpperCase());
      }
      position++;
    }
View Full Code Here

Examples of net.sf.nlpshell.domain.word.verb.Verb

    }
    return frameString;
  }

  public Verb getVerb() {
    Verb v = null;
    for (FrameItem frameItem : this.components) {
      if (frameItem.pos instanceof Verb) {
        v = (Verb) frameItem.pos;
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.