Package net.sf.jabref.bst

Examples of net.sf.jabref.bst.VM$Variable


    assertEquals(VM.TRUE, vm.getStack().pop());
  }

  public void testWhile() throws RecognitionException, IOException {

    VM vm = new VM(
      "STRINGS { t }            "
        + "FUNCTION {not}  {   "
        + " { #0 } { #1 }  if$ } "
        + "FUNCTION {n.dashify}              "
        + "{ \"HELLO-WORLD\"                 "
        + "  't :=                           "
        + " \"\"                                                 "
        + "     { t empty$ not }                 "
        + "     { t #1 #1 substring$ \"-\" =                      "
        + "       { t #1 #2 substring$ \"--\" = not "
        + "            { \"--\" *                                       "
        + "              t #2 global.max$ substring$ 't :=                 "
        + "            }                                                    "
        + "            {   { t #1 #1 substring$ \"-\" = }                "
        + "                { \"-\" *                                         "
        + "                  t #2 global.max$ substring$ 't :=               "
        + "                }                                                  "
        + "              while$                                                                  "
        + "            }                                                                  "
        + "          if$                                                                  "
        + "        }                                                                  "
        + "        { t #1 #1 substring$ *                                       "
        + "          t #2 global.max$ substring$ 't :=                          "
        + "        }                                                                  "
        + "        if$                                                                  "
        + "      }                                                                  "
        + "    while$                                                                  "
        + "  }                                                                  "
        + " EXECUTE {n.dashify} ");

    Vector<BibtexEntry> v = new Vector<BibtexEntry>();
    vm.run(v);

    assertEquals(1, vm.getStack().size());
    assertEquals("HELLO--WORLD", vm.getStack().pop());
  }
View Full Code Here


    assertEquals("HELLO--WORLD", vm.getStack().pop());
  }

  public void testType() throws RecognitionException, IOException {

    VM vm = new VM(
      ""
        + "ENTRY  { title }  { }  { label }"
        + "FUNCTION {presort} { cite$ 'sort.key$ := } ITERATE { presort } SORT FUNCTION {test} { type$ } ITERATE { test }");

    Vector<BibtexEntry> v = new Vector<BibtexEntry>();
    v.add(bibtexString2BibtexEntry("@article{a, author=\"AAA\"}"));
    v.add(bibtexString2BibtexEntry("@book{b, author=\"BBB\"}"));
    v.add(bibtexString2BibtexEntry("@misc{c, author=\"CCC\"}"));
    v.add(bibtexString2BibtexEntry("@inproceedings{d, author=\"DDD\"}"));
    vm.run(v);

    assertEquals(4, vm.getStack().size());
    assertEquals("Inproceedings", vm.getStack().pop());
    assertEquals("Misc", vm.getStack().pop());
    assertEquals("Book", vm.getStack().pop());
    assertEquals("Article", vm.getStack().pop());
  }
View Full Code Here

    assertEquals("Article", vm.getStack().pop());
  }

  public void testMissing() throws RecognitionException, IOException {

    VM vm = new VM( //
      "ENTRY    { title }  { }  { label } " + //
        "FUNCTION {presort} { cite$ 'sort.key$ := } " + //
        "ITERATE  {presort} " + //
        "READ SORT " + //
        "FUNCTION {test}{ title missing$ cite$ } " + //
        "ITERATE  { test }");

    Vector<BibtexEntry> v = new Vector<BibtexEntry>();
    v.add(t1BibtexEntry());
    v.add(bibtexString2BibtexEntry("@article{test, author=\"No title\"}"));
    vm.run(v);

    assertEquals(4, vm.getStack().size());

    assertEquals("test", vm.getStack().pop());
    assertEquals(new Integer(1), vm.getStack().pop());
    assertEquals("canh05", vm.getStack().pop());
    assertEquals(new Integer(0), vm.getStack().pop());
  }
View Full Code Here

    assertEquals(new Integer(0), vm.getStack().pop());
  }

  public void testFormatName() throws RecognitionException, IOException {
    {
      VM vm = new VM(
        "FUNCTION {format}{ \"Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin\" #1 \"{vv~}{ll}{, jj}{, f}?\" format.name$ }"
          + "EXECUTE {format}");

      Vector<BibtexEntry> v = new Vector<BibtexEntry>();
      vm.run(v);
      assertEquals("de~la Vall{\\'e}e~Poussin, C.~L. X.~J?", (String) vm.getStack().pop());
      assertEquals(0, vm.getStack().size());
    }
    {
      VM vm = new VM("ENTRY  { author }  { }  { label } "
        + "FUNCTION {presort} { cite$ 'sort.key$ := } " + "ITERATE { presort } " + "READ "
        + "SORT " + "FUNCTION {format}{ author #2 \"{vv~}{ll}{, jj}{, f}?\" format.name$ }"
        + "ITERATE {format}");

      Vector<BibtexEntry> v = new Vector<BibtexEntry>();
      v.add(t1BibtexEntry());
      v
        .add(bibtexString2BibtexEntry("@book{test, author=\"Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin\"}"));
      vm.run(v);
      assertEquals("de~la Vall{\\'e}e~Poussin, C.~L. X.~J?", vm.getStack().pop());
      assertEquals("Annabi, H?", vm.getStack().pop());
      assertEquals(0, vm.getStack().size());
    }
  }
View Full Code Here

    }
  }

  public void testCallType() throws RecognitionException, IOException {

    VM vm = new VM(
      "ENTRY  { title }  { }  { label } FUNCTION {presort} { cite$ 'sort.key$ := } ITERATE { presort } READ SORT "
        + "FUNCTION {inproceedings}{ \"InProceedings called on \" title * } "
        + "FUNCTION {book}{ \"Book called on \" title * } " + " ITERATE { call.type$ }");

    Vector<BibtexEntry> v = new Vector<BibtexEntry>();
    v.add(t1BibtexEntry());
    v.add(bibtexString2BibtexEntry("@book{test, title=\"Test\"}"));
    vm.run(v);

    assertEquals(2, vm.getStack().size());

    assertEquals("Book called on Test", vm.getStack().pop());
    assertEquals(
      "InProceedings called on Effective work practices for floss development: A model and propositions",
      vm.getStack().pop());
    assertEquals(0, vm.getStack().size());
  }
View Full Code Here

    assertEquals(0, vm.getStack().size());
  }

  public void testIterate() throws RecognitionException, IOException {

    VM vm = new VM("" + "ENTRY  { " + "  address " + "  author " + "  title " + "  type "
      + "}  {}  { label } " + "FUNCTION {test}{ cite$ } " + "READ " + "ITERATE { test }");

    Vector<BibtexEntry> v = new Vector<BibtexEntry>();
    v.add(t1BibtexEntry());

    v.add(bibtexString2BibtexEntry("@article{test, title=\"BLA\"}"));

    vm.run(v);

    assertEquals(2, vm.getStack().size());

    String s1 = (String) vm.getStack().pop();
    String s2 = (String) vm.getStack().pop();

    if (s1.equals("canh05")) {
      assertEquals("test", s2);
    } else {
      assertEquals("canh05", s2);
View Full Code Here

    }
  }

  public void testWidth() throws RecognitionException, IOException {

    VM vm = new VM("ENTRY  { " + "  address " + "  author " + "  title " + "  type "
      + "}  {}  { label } " + //
      "STRINGS { longest.label } " + //
      "INTEGERS { number.label longest.label.width } " + //
      "FUNCTION {initialize.longest.label} " + //
      "{ \"\" 'longest.label := " + //
      "  #1 'number.label := " + //
      "  #0 'longest.label.width := " + //
      "} " + //
      " " + //
      "    FUNCTION {longest.label.pass} " + //
      "    { number.label int.to.str$ 'label := " + //
      "      number.label #1 + 'number.label := " + //
      "      label width$ longest.label.width > " + //
      "        { label 'longest.label := " + //
      "          label width$ 'longest.label.width := " + //
      "        } " + //
      "        'skip$ " + //
      "      if$ " + //
      "    } " + //
      " " + //
      "    EXECUTE {initialize.longest.label} " + //
      " " + //
      "    ITERATE {longest.label.pass} " + //
      "FUNCTION {begin.bib} " + //
      "{ preamble$ empty$" + //
      "    'skip$" + //
      "    { preamble$ write$ newline$ }" + //
      "  if$" + //
      "  \"\\begin{thebibliography}{\"  longest.label  * \"}\" *" + //
      "}" + //
      "EXECUTE {begin.bib}" + //
      "");//

    Vector<BibtexEntry> v = new Vector<BibtexEntry>();
    v.add(t1BibtexEntry());

    vm.run(v);

    assertTrue(vm.getIntegers().containsKey("longest.label.width"));
    assertEquals("\\begin{thebibliography}{1}", vm.getStack().pop());
  }
View Full Code Here

    assertEquals("\\begin{thebibliography}{1}", vm.getStack().pop());
  }

  public void testVMSwap() throws RecognitionException, IOException {

    VM vm = new VM("FUNCTION {a}{ #3 \"Hallo\" swap$ } EXECUTE { a }");

    Vector<BibtexEntry> v = new Vector<BibtexEntry>();
    vm.run(v);

    assertEquals(2, vm.getStack().size());
    assertEquals(new Integer(3), vm.getStack().pop());
    assertEquals("Hallo", vm.getStack().pop());
  }
View Full Code Here

      + "  year = {2005},\n" + "  owner = {oezbek},\n" + "  timestamp = {2006.05.29},\n"
      + "  url = {http://james.howison.name/publications.html}}\n";
  }

  public void testHypthenatedName() throws RecognitionException, IOException {
    VM vm = new VM(new File("src/tests/net/sf/jabref/bst/abbrv.bst"));
    Vector<BibtexEntry> v = new Vector<BibtexEntry>();
    v.add(bibtexString2BibtexEntry("@article{canh05, author = \"Jean-Paul Sartre\" }"));
    assertTrue(vm.run(v).indexOf("J.-P. Sartre") != -1);
  }
View Full Code Here

        List<GradsVariable>  vars  = gradsDDF.getVariables();
        List<GradsAttribute> attrs = gradsDDF.getAttributes();
        //TODO: ensembles
        List<GradsDimension>       dims = gradsDDF.getDimensions();
        Variable                   v;
        int                        numZ  = 0;
        HashMap<String, Dimension> zDims = new HashMap<String, Dimension>();
        for (GradsDimension dim : dims) {
            String    name  = getVarName(dim);
            int       size  = dim.getSize();
            Dimension ncDim = new Dimension(name, size, true);
            ncFile.addDimension(null, ncDim);
            if (name.equals(ENS_VAR)) {
                v = new Variable(ncFile, null, null, name, DataType.STRING,
                                 name);
                v.addAttribute(new Attribute("standard_name", "ensemble"));
                v.addAttribute(new Attribute(_Coordinate.AxisType,
                                             AxisType.Ensemble.toString()));
                List<String> names =
                    gradsDDF.getEnsembleDimension().getEnsembleNames();
                String[] nameArray = new String[names.size()];
                for (int i = 0; i < nameArray.length; i++) {
                    nameArray[i] = names.get(i);
                }
                Array dataArray = Array.factory(DataType.STRING,
                                      new int[] { nameArray.length },
                                      nameArray);
                v.setCachedData(dataArray, false);
            } else {
                double[] vals = dim.getValues();
                v = new Variable(ncFile, null, null, name, DataType.DOUBLE,
                                 name);
                v.addAttribute(new Attribute("units", dim.getUnit()));
                if (name.equals(Y_VAR)) {
                    v.addAttribute(new Attribute("long_name", "latitude"));
                    v.addAttribute(new Attribute("standard_name",
                            "latitude"));
                    v.addAttribute(new Attribute("axis", "Y"));
                    sizeY = dim.getSize();
                    v.addAttribute(new Attribute(_Coordinate.AxisType,
                            AxisType.Lat.toString()));
                } else if (name.equals(X_VAR)) {
                    v.addAttribute(new Attribute("long_name", "longitude"));
                    v.addAttribute(new Attribute("standard_name",
                            "longitude"));
                    v.addAttribute(new Attribute("axis", "X"));
                    v.addAttribute(new Attribute(_Coordinate.AxisType,
                            AxisType.Lon.toString()));
                    sizeX = dim.getSize();
                } else if (name.equals(Z_VAR)) {
                    numZ = size;
                    zDims.put(name, ncDim);
                    v.addAttribute(new Attribute("long_name", "level"));
                    addZAttributes(dim, v);
                } else if (name.equals(TIME_VAR)) {
                    v.addAttribute(new Attribute("long_name", "time"));
                    v.addAttribute(new Attribute(_Coordinate.AxisType,
                            AxisType.Time.toString()));
                }
                ArrayDouble.D1 varArray = new ArrayDouble.D1(size);
                for (int i = 0; i < vals.length; i++) {
                    varArray.set(i, vals[i]);
                }
                v.setCachedData(varArray, false);
            }
            ncFile.addVariable(null, v);
        }
        if (numZ > 0) {
            GradsDimension zDim = gradsDDF.getZDimension();
            double[]       vals = zDim.getValues();
            for (GradsVariable var : vars) {
                int nl = var.getNumLevels();
                if ((nl > 0) && (nl != numZ)) {
                    String name = Z_VAR + nl;
                    if (zDims.get(name) == null) {
                        Dimension ncDim = new Dimension(name, nl, true);
                        ncFile.addDimension(null, ncDim);
                        Variable vz = new Variable(ncFile, null, null, name,
                                          DataType.DOUBLE, name);
                        vz.addAttribute(new Attribute("long_name", name));
                        vz.addAttribute(new Attribute("units",
                                zDim.getUnit()));
                        addZAttributes(zDim, vz);
                        ArrayDouble.D1 varArray = new ArrayDouble.D1(nl);
                        for (int i = 0; i < nl; i++) {
                            varArray.set(i, vals[i]);
                        }
                        vz.setCachedData(varArray, false);
                        ncFile.addVariable(null, vz);
                        zDims.put(name, ncDim);
                    }
                }
            }
        }
        zDims = null;
        for (GradsVariable var : vars) {
            String coords = "latitude longitude";
            int    nl     = var.getNumLevels();
            if (nl > 0) {
                if (nl == numZ) {
                    coords = "level " + coords;
                } else {
                    coords = Z_VAR + nl + " " + coords;
                }
            }
            coords = "time " + coords;
            if (gradsDDF.getEnsembleDimension() != null) {
                coords = "ensemble " + coords;
            }
            v = new Variable(ncFile, null, null, var.getName(),
                             DataType.FLOAT, coords);
            v.addAttribute(new Attribute("long_name", var.getDescription()));
            if (var.getUnitName() != null) {
                v.addAttribute(new Attribute("units", var.getUnitName()));
            }
View Full Code Here

TOP

Related Classes of net.sf.jabref.bst.VM$Variable

Copyright © 2018 www.massapicom. 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.