Beispiel #1
0
  public static PetriNet convert(ConfigurableEPC baseEPC) {
    HashMap<EPCFunction, Transition> functionActivityMapping;
    HashMap<EPCConnector, Place> xorconnectorChoiceMapping;

    // HV: Initialize the mappings.
    functionActivityMapping = new HashMap<EPCFunction, Transition>();
    xorconnectorChoiceMapping = new HashMap<EPCConnector, Place>();

    // Check to use the weights if necessary
    // HV: Add both mappings. On completion, these will be filledd.
    PetriNet petrinet =
        EPCToPetriNetConverter.convert(
            baseEPC, new HashMap(), functionActivityMapping, xorconnectorChoiceMapping);

    HashSet visible = new HashSet();

    // HV: The next block is taken care of by the functionActivityMapping
    // below.
    /*
     * Iterator it = petrinet.getTransitions().iterator(); while
     * (it.hasNext()) { Transition t = (Transition) it.next(); if (t.object
     * instanceof EPCFunction) { // if (t.getLogEvent() != null) { // Add
     * transitions with LogEvent (i.e. referring to functions)
     * visible.add(t); } }
     */

    // HV: Prevent the places mapped onto from being reduced.
    visible.addAll(functionActivityMapping.values());
    visible.addAll(xorconnectorChoiceMapping.values());
    Message.add(visible.toString(), Message.DEBUG);

    Iterator it = petrinet.getPlaces().iterator();
    while (it.hasNext()) {
      Place p = (Place) it.next();
      if (p.inDegree() * p.outDegree() == 0) {
        // Add Initial and final places to visible, i.e. places that
        // refer to in and output events
        visible.add(p);
      }
    }

    // Reduce the PetriNet with Murata rules, while keeping the visible ones
    PetriNetReduction pnred = new PetriNetReduction();
    pnred.setNonReducableNodes(visible);

    HashMap pnMap = new HashMap(); // Used to map pre-reduction nodes to
    // post-reduction nodes.
    PetriNet reduced = pnred.reduce(petrinet, pnMap);

    if (reduced != petrinet) {
      // Update both mappings from pre-reduction nodes to post-reduction
      // nodes.
      HashMap<EPCFunction, Transition> newFunctionActivityMapping =
          new HashMap<EPCFunction, Transition>();
      for (EPCFunction function : functionActivityMapping.keySet()) {
        Transition transition = (Transition) functionActivityMapping.get(function);
        if (pnMap.keySet().contains(transition)) {
          newFunctionActivityMapping.put(function, (Transition) pnMap.get(transition));
        }
      }
      functionActivityMapping = newFunctionActivityMapping;
      HashMap<EPCConnector, Place> newXorconnectorChoiceMapping =
          new HashMap<EPCConnector, Place>();
      for (EPCConnector connector : xorconnectorChoiceMapping.keySet()) {
        Place place = (Place) xorconnectorChoiceMapping.get(connector);
        if (pnMap.keySet().contains(place)) {
          newXorconnectorChoiceMapping.put(connector, (Place) pnMap.get(place));
        }
      }
      xorconnectorChoiceMapping = newXorconnectorChoiceMapping;
    }
    reduced.makeClusters();

    // filter the \nunknown:normal
    ArrayList<Transition> alTrans = reduced.getVisibleTasks();
    for (int i = 0; i < alTrans.size(); i++) {
      Transition t = alTrans.get(i);
      String id = t.getIdentifier();
      int idx = id.indexOf("\\nunknown:normal");
      if (idx > 0) {
        id = id.substring(0, idx);
      }
      // �˴������ֵ��ѯ�滻���е�label
      String mappedId = htDict.get(id);
      if (mappedId != null) {
        t.setIdentifier(mappedId);
      } else {
        t.setIdentifier(id);
      }
    }

    return reduced;
  }
  public void testPlaceAsJSON() throws Exception {
    List<Place> places =
        PlaceJSONImpl.createPlaceList(
            getJSONObjectFromClassPath("/dao/reverse-geocode.json")
                .getJSONObject("result")
                .getJSONArray("places"),
            null,
            conf);
    Place place = places.get(0);
    Assert.assertEquals("SoMa", place.getName());
    Assert.assertEquals("US", place.getCountryCode());
    Assert.assertEquals("2b6ff8c22edd9576", place.getId());
    Assert.assertEquals("", place.getCountry());
    Assert.assertEquals("neighborhood", place.getPlaceType());
    Assert.assertEquals("http://api.twitter.com/1/geo/id/2b6ff8c22edd9576.json", place.getURL());
    Assert.assertEquals("SoMa, San Francisco", place.getFullName());
    Assert.assertEquals("Polygon", place.getBoundingBoxType());
    GeoLocation[][] boundingBox = place.getBoundingBoxCoordinates();
    Assert.assertEquals(1, boundingBox.length);
    Assert.assertEquals(4, boundingBox[0].length);
    Assert.assertEquals(37.76893497, boundingBox[0][0].getLatitude());
    Assert.assertEquals(-122.42284884, boundingBox[0][0].getLongitude());
    Assert.assertEquals(37.76893497, boundingBox[0][1].getLatitude());
    Assert.assertEquals(-122.3964, boundingBox[0][1].getLongitude());
    Assert.assertEquals(37.78752897, boundingBox[0][2].getLatitude());
    Assert.assertEquals(-122.3964, boundingBox[0][2].getLongitude());
    Assert.assertEquals(37.78752897, boundingBox[0][3].getLatitude());
    Assert.assertEquals(-122.42284884, boundingBox[0][3].getLongitude());
    Assert.assertNull(place.getGeometryType());
    Assert.assertNull(place.getGeometryCoordinates());

    Place[] containedWithinArray = place.getContainedWithIn();
    Assert.assertEquals(1, containedWithinArray.length);
    Place containedWithin = containedWithinArray[0];
    Assert.assertNull(containedWithin.getContainedWithIn());
    Assert.assertEquals("San Francisco", containedWithin.getName());
    Assert.assertEquals("US", containedWithin.getCountryCode());
    Assert.assertEquals("5a110d312052166f", containedWithin.getId());
    Assert.assertEquals("", containedWithin.getCountry());
    Assert.assertEquals("city", containedWithin.getPlaceType());
    Assert.assertEquals(
        "http://api.twitter.com/1/geo/id/5a110d312052166f.json", containedWithin.getURL());
    Assert.assertEquals("San Francisco", containedWithin.getFullName());
    boundingBox = containedWithin.getBoundingBoxCoordinates();
    Assert.assertEquals("Polygon", place.getBoundingBoxType());
    Assert.assertEquals(1, boundingBox.length);
    Assert.assertEquals(4, boundingBox[0].length);
    Assert.assertEquals(37.70813196, boundingBox[0][0].getLatitude());
    Assert.assertEquals(-122.51368188, boundingBox[0][0].getLongitude());
    Assert.assertEquals(37.70813196, boundingBox[0][1].getLatitude());
    Assert.assertEquals(-122.35845384, boundingBox[0][1].getLongitude());
    Assert.assertEquals(37.83245301, boundingBox[0][2].getLatitude());
    Assert.assertEquals(-122.35845384, boundingBox[0][2].getLongitude());
    Assert.assertEquals(37.83245301, boundingBox[0][3].getLatitude());
    Assert.assertEquals(-122.51368188, boundingBox[0][3].getLongitude());

    Assert.assertNull(place.getGeometryType());
    Assert.assertNull(place.getGeometryCoordinates());

    place = new PlaceJSONImpl(getJSONObjectFromClassPath("/dao/5a110d312052166f.json"), null);
    Assert.assertNotNull(place.getGeometryType());
    Assert.assertNotNull(place.getGeometryCoordinates());

    // Test that a geo object with geometry type "Point" works.
    place = new PlaceJSONImpl(getJSONObjectFromClassPath("/dao/3c6797665e2d42eb.json"), null);
    Assert.assertEquals(place.getGeometryType(), "Point");
    Assert.assertNotNull(place.getGeometryCoordinates());

    place = new PlaceJSONImpl(getJSONObjectFromClassPath("/dao/c3f37afa9efcf94b.json"), null);
    // MultiPolygon is not supported by twitter4j yet, so we set geometryType to null
    Assert.assertNull(place.getGeometryType());
    Assert.assertNull(place.getGeometryCoordinates());
  }