[procilege commit] r74 - in trunk/procilege/src: main/java/merisis/traitspace main/java/merisis/traitspace/impl test...

0 views
Skip to first unread message

codesite...@google.com

unread,
Jun 9, 2007, 2:27:10 PM6/9/07
to procil...@googlegroups.com
Author: lcgong
Date: Sat Jun 9 11:26:55 2007
New Revision: 74

Added:
trunk/procilege/src/test/java/merisis/traitspace/EntityHappen3Test.java
Modified:
trunk/procilege/src/main/java/merisis/traitspace/EntityHappen.java
trunk/procilege/src/main/java/merisis/traitspace/HappenReaction.java
trunk/procilege/src/main/java/merisis/traitspace/impl/HistoryView.java
trunk/procilege/src/main/java/merisis/traitspace/impl/SketchImpl.java
trunk/procilege/src/main/java/merisis/traitspace/impl/TraitSpaceImpl.java
trunk/procilege/src/test/java/merisis/traitspace/Sketch1Test.java
trunk/procilege/src/test/java/merisis/traitspace/Sketch4Test.java
trunk/procilege/src/test/java/merisis/traitspace/Sketch7Test.java

Log:
[Issue 34]rippling of reaction.

Modified: trunk/procilege/src/main/java/merisis/traitspace/EntityHappen.java
==============================================================================
--- trunk/procilege/src/main/java/merisis/traitspace/EntityHappen.java (original)
+++ trunk/procilege/src/main/java/merisis/traitspace/EntityHappen.java Sat Jun 9 11:26:55 2007
@@ -1,13 +1,17 @@
package merisis.traitspace;

+import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

+import org.apache.solr.util.OpenBitSet;
+
import merisis.MerisisVM;
import merisis.contentcloud.ContentCloud;
import merisis.util.BitUtil;

import com.google.inject.Inject;
+import com.google.inject.Injector;

public class EntityHappen {

@@ -20,38 +24,12 @@
@Inject
private ContentCloud cloud;

- public void happen(long[] ontos, Object object) {
-
- mvm.give(ontos);
- mvm.source();
- mvm.focus();
- long[] onto = mvm.read();
-
- long occ1 = -1;
- long occ2 = -1;
- long objc;
- if (onto == null || onto.length == 0) {
-
- occ1 = mvm.occur(ontos);
- } else if (onto.length == 1) {
-
- occ1 = onto[0];
- } else {
- throw new AmbiguityException(ontos);
- }
- objc = cloud.occur(object);
- occ2 = mvm.occur(occ1, objc);
-
- if (logger.isLoggable(Level.FINEST)) {
+ @Inject
+ private Injector injector;

- StringBuilder sb = new StringBuilder();
- sb.append("((ontos {");
- BitUtil.format(sb, onto, ",");
- sb.append("}): " + occ1);
- sb.append(", object:" + objc);
- sb.append("):" + occ2);
- logger.finest(sb.toString());
- }
+ public void happen(long[] ontos, Object object) {
+
+ happen(ontos, object, -1);
}

public void happen(long[] ontos, Object object, long place) {
@@ -74,12 +52,17 @@
throw new AmbiguityException(ontos);
}

- mvm.give(place);
- mvm.stepin();
- try {
+ if (place == -1) {
objc = cloud.occur(object);
- } finally {
- mvm.stepout();
+ } else {
+
+ mvm.give(place);
+ mvm.stepin();
+ try {
+ objc = cloud.occur(object);
+ } finally {
+ mvm.stepout();
+ }
}

occ2 = mvm.occur(occ1, objc);
@@ -88,12 +71,14 @@

StringBuilder sb = new StringBuilder();
sb.append("((ontos {");
- BitUtil.format(sb, onto, ",");
+ BitUtil.format(sb, ontos, ",");
sb.append("}): " + occ1);
sb.append(", object:" + objc);
sb.append("):" + occ2);
logger.finest(sb.toString());
}
+
+ ripple(occ2);
}

public Object retrieve(long[] ontos) {
@@ -132,8 +117,64 @@
return cloud.retrieve(onto[0]);
}

- public void ripple(long[] ontos, HappenReaction reaction) {
+ private HashMap<OpenBitSet, Class<? extends HappenReaction>> reactionMap = new HashMap<OpenBitSet, Class<? extends HappenReaction>>();

+ public void ripple(long center) {
+
+ for (OpenBitSet k : reactionMap.keySet()) {
+
+ mvm.give(BitUtil.toArray(k));
+ mvm.source();
+ mvm.give(center);
+ mvm.focus();
+ long[] test = mvm.read();
+
+ if (test == null)
+ continue;
+
+ if (logger.isLoggable(Level.FINEST)) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("rippling, center: " + center);
+ sb.append(", reacted-ontos: {");
+ BitUtil.format(sb, k, ",");
+ sb.append("}");
+ logger.finest(sb.toString());
+ }
+
+ Class<? extends HappenReaction> cls;
+ cls = reactionMap.get(k);
+ try {
+ HappenReaction r = cls.newInstance();
+ injector.injectMembers(r);
+
+ //
+ mvm.give(center);
+ mvm.source();
+ mvm.give(center);
+ mvm.focus();
+ mvm.autobeam();
+ try {
+ mvm.give(BitUtil.toArray(k));
+ mvm.tprism();
+ mvm.tcomplementary();
+ } finally {
+ mvm.stepout();
+ }
+ long[] pts = mvm.read();
+ if (pts == null) {
+ continue;
+ }
+
+ r.happen(pts);
+ } catch (Exception e) {
+ logger.log(Level.WARNING, e.getMessage(), e);
+ }
+ }
}

+ public void ripple(long[] ontos, Class<? extends HappenReaction> reactor) {
+
+ OpenBitSet bs = BitUtil.bitsetOrArray(new OpenBitSet(), ontos);
+ reactionMap.put(bs, reactor);
+ }
}

Modified: trunk/procilege/src/main/java/merisis/traitspace/HappenReaction.java
==============================================================================
--- trunk/procilege/src/main/java/merisis/traitspace/HappenReaction.java (original)
+++ trunk/procilege/src/main/java/merisis/traitspace/HappenReaction.java Sat Jun 9 11:26:55 2007
@@ -2,5 +2,5 @@

public interface HappenReaction {

- public void happen(long point);
+ public void happen(long[] points);
}

Modified: trunk/procilege/src/main/java/merisis/traitspace/impl/HistoryView.java
==============================================================================
--- trunk/procilege/src/main/java/merisis/traitspace/impl/HistoryView.java (original)
+++ trunk/procilege/src/main/java/merisis/traitspace/impl/HistoryView.java Sat Jun 9 11:26:55 2007
@@ -4,7 +4,11 @@

public class HistoryView {

- OpenBitSet bound;
+ OpenBitSet background;

- OpenBitSet pickup;
-}
+ OpenBitSet sources;
+
+ OpenBitSet guide;
+
+ OpenBitSet focus;
+}
\ No newline at end of file

Modified: trunk/procilege/src/main/java/merisis/traitspace/impl/SketchImpl.java
==============================================================================
--- trunk/procilege/src/main/java/merisis/traitspace/impl/SketchImpl.java (original)
+++ trunk/procilege/src/main/java/merisis/traitspace/impl/SketchImpl.java Sat Jun 9 11:26:55 2007
@@ -23,286 +23,86 @@
logger = Logger.getLogger(SketchImpl.class.getName());
}

- private OpenBitSet part = new OpenBitSet();
- private OpenBitSet bound = new OpenBitSet();
+ private OpenBitSet backgroud = new OpenBitSet();

- private OpenBitSet supremum;
-
- private OpenBitSet tcomplementary;
+ private OpenBitSet source = new OpenBitSet();

private OpenBitSet tspectrum;

private OpenBitSet tprism;

- private long infimum;
-
- private OpenBitSet focused;
+ private OpenBitSet focus;

private History history;

private Map<Long, OpenBitSet> footprintsMap = new HashMap<Long, OpenBitSet>();

- private OpenBitSet sliced;
-
- private boolean isDirty = true;
-
public SketchImpl(History history) {

this.history = history;
}

- public void setBoundPart(OpenBitSet bound, OpenBitSet part) {
+ public void setBackground(OpenBitSet bg) {

- this.bound = bound;
- this.part = part;
-
- if (!isDirty)
- isDirty = true;
+ this.backgroud = bg;
}

- public HistoricalHierarchyImpl historical() {
-
- if (isDirty) {
-
- search();
- }
-
- return new HistoricalHierarchyImpl(footprintsMap, sliced);
- }
-
- public OpenBitSet focus() {
-
- if (isDirty) {
-
- search();
- }
+ public void setSource(OpenBitSet bound) {

- return focused;
+ this.source = bound;
}

- public OpenBitSet tspectrum(OpenBitSet traits) {
-
- if (isDirty)
- search();
-
- if (focused == null)
- return null;
-
- tprism = traits;
-
- OpenBitSet queue = new OpenBitSet();
- queue.or(tprism);
-
- // traverse the traits
- OpenBitSet involved = new OpenBitSet();
- while (true) {
-
- long node = queue.nextSetBit(0);
- if (node < 0)
- break;
-
- queue.clear(node);
- involved.set(node);
-
- OpenBitSet nodeFootprints = footprintsMap.get(node);
- if (nodeFootprints == null) {
- nodeFootprints = new OpenBitSet();
- nodeFootprints.set(node);
- footprintsMap.put(node, nodeFootprints);
- }
-
- long[] nextpoints = history.next(node);
- if (nextpoints == null)
- continue;
-
- for (int j = 0; j < nextpoints.length; j++) {
-
- long point = nextpoints[j];
-
- OpenBitSet footprints = footprintsMap.get(point);
- if (footprints == null) {
- footprints = new OpenBitSet();
- footprintsMap.put(point, footprints);
- }
-
- footprints.set(point);
- footprints.or(nodeFootprints);
-
- queue.set(point);
- }
- }
-
- if (logger.isLoggable(Level.FINEST)) {
- StringBuilder sb = new StringBuilder();
- logger.finest(dumpStateDetail(sb).toString());
- }
-
- OpenBitSet selected = new OpenBitSet();
-
- long numOfTraits = traits.cardinality();
-
- queue = new OpenBitSet();
- queue.or(focused);
- involved = new OpenBitSet();
- while (true) {
-
- long node = queue.nextSetBit(0);
- if (node < 0)
- break;
-
- queue.clear(node);
- involved.set(node);
-
- OpenBitSet nodeFootprints = footprintsMap.get(node);
- if (nodeFootprints == null)
- continue;
-
- if (intersectionCount(bound, nodeFootprints) == 0
- || intersectionCount(traits, nodeFootprints) == 0) {
-
- continue;
- }
-
- logger.info("node: " + node);
-
- long[] preivios = history.previous(node);
- if (preivios == null)
- continue;
-
- boolean nosup = false;
-
- for (int j = 0; j < preivios.length; j++) {
-
- long point = preivios[j];
-
- OpenBitSet footprints = footprintsMap.get(point);
- if (footprints == null)
- continue;
-
- if (intersectionCount(bound, footprints) == 0)
- continue;
-
- if (intersectionCount(tprism, footprints) == numOfTraits) {
-
- queue.set(point);
- nosup = true;
- }
- }
-
- if (!nosup) {
- selected.set(node);
- }
- }
-
- tspectrum = selected;
-
- if (logger.isLoggable(Level.FINEST)) {
- StringBuilder sb = new StringBuilder();
- sb.append("on traits {");
- BitUtil.format(sb, tprism, ",");
- sb.append("}, t-spectrum: {");
- BitUtil.format(sb, tspectrum, ",");
- sb.append("}");
- logger.finest(sb.toString());
- }
+ public void setPart(OpenBitSet part) {

- return tspectrum;
+ this.focus = part;
}

- public OpenBitSet tcomplementary() {
-
- if (focused == null || focused.isEmpty())
- return null;
-
- // negative spectrum
- OpenBitSet nselected = new OpenBitSet();
- for (long node = focused.nextSetBit(0); node >= 0; node = focused
- .nextSetBit(node + 1)) {
-
- long[] preivios = history.previous(node);
- if (preivios == null)
- continue;
-
- for (int j = 0; j < preivios.length; j++) {
-
- long point = preivios[j];
-
- if (tprism.get(point))
- continue;
-
- OpenBitSet footprints = footprintsMap.get(point);
- if (footprints == null)
- continue;
-
- if (intersectionCount(bound, footprints) == 0)
- continue;
-
- if (tspectrum != null
- && intersectionCount(tspectrum, footprints) > 0) {
- continue;
- }
-
- nselected.set(point);
- }
- }
+ public HistoricalHierarchyImpl historical() {

- OpenBitSet min = new OpenBitSet();
- minimumOfTraits(min, nselected);
- tcomplementary = min;
+ // if (isDirty) {
+ //
+ // search();
+ // }
+ //
+ // return new HistoricalHierarchyImpl(footprintsMap, sliced);

- if (logger.isLoggable(Level.FINEST)) {
- StringBuilder sb = new StringBuilder();
- sb.append("t-spectrum complementary: {");
- BitUtil.format(sb, tcomplementary, ",");
- sb.append("}");
- logger.finest(sb.toString());
- }
-
- return tcomplementary;
+ throw new UnsupportedOperationException();
}

- private void minimumOfTraits(OpenBitSet minimum, OpenBitSet nselected) {
-
- if (nselected == null || nselected.isEmpty())
- return;
-
- long p = nselected.nextSetBit(0);
- minimum.set(p);
- for (p = nselected.nextSetBit(p + 1); p >= 0; p = nselected
- .nextSetBit(p + 1)) {
+ public OpenBitSet focus() {

- OpenBitSet fp1 = footprintsMap.get(p);
- if (OpenBitSet.andNotCount(fp1, minimum) > 0) {
- minimum.andNot(fp1);
- minimum.set(p);
- }
- }
- }
+ OpenBitSet part = focus;

- private void search() {
-
if (logger.isLoggable(Level.FINEST)) {
StringBuilder sb = new StringBuilder();
- sb.append("sources: {");
- BitUtil.format(sb, bound, ",");
- sb.append("}, parts: {");
+ sb.append("background: {");
+ BitUtil.format(sb, backgroud, ",");
+ sb.append("}, source: {");
+ BitUtil.format(sb, source, ",");
+ sb.append("}, guide: {");
BitUtil.format(sb, part, ",");
sb.append("}");
logger.finest(sb.toString());
}

+ OpenBitSet bound = new OpenBitSet();
+ if (backgroud != null)
+ bound.or(backgroud);

- if (bound == null)
- return;
+ if (source != null)
+ bound.or(source);
+
+ if (bound.isEmpty())
+ return null;

- focused = null;
- sliced = null;
+ focus = null;
+ OpenBitSet sliced = null;

OpenBitSet queue = new OpenBitSet();
queue.or(bound);

boolean sdetermined = false;
- supremum = new OpenBitSet();
+ OpenBitSet supremum = new OpenBitSet();
long numOfBoundPoints = bound.cardinality();
if (numOfBoundPoints == 1) {

@@ -386,9 +186,9 @@
}

if (supremum.isEmpty())
- return;
+ return null;

- infimum = -1;
+ long infimum = -1;
if (part != null && !part.isEmpty()) {

while (true) {
@@ -441,7 +241,7 @@
if (part != null && !part.isEmpty() && infimum < 0) {
sliced = null;
logger.finest("no infimum");
- return;
+ return null;
}

sliced = new OpenBitSet();
@@ -477,7 +277,7 @@

if (logger.isLoggable(Level.FINEST)) {
StringBuilder sb = new StringBuilder();
- sb.append("siliced, supported by parts: ");
+ sb.append("siliced: ");
BitUtil.format(sb, sliced, ",");
logger.finest(sb.toString());
}
@@ -488,33 +288,257 @@
logger.finest(dumpStateDetail(sb).toString());
}

- isDirty = false;
-
- // TODO improve it soon.
- this.focused = historical().rollHistory(0);
+ HistoricalHierarchyImpl hhi;
+ hhi = new HistoricalHierarchyImpl(footprintsMap, sliced);
+ this.focus = hhi.rollHistory(0);
+ // OpenBitSet minimum = new OpenBitSet();
+ // minimumOfTraits(minimum, sliced);
+ // this.focused = minimum;
if (logger.isLoggable(Level.FINEST)) {
StringBuilder sb = new StringBuilder();
sb.append("focus: ");
- BitUtil.format(sb, focused, ",");
+ BitUtil.format(sb, focus, ",");
+ logger.finest(sb.toString());
+ }
+
+ return focus;
+ }
+
+ public OpenBitSet tspectrum(OpenBitSet traits) {
+
+ if (logger.isLoggable(Level.FINEST)) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("background: {");
+ BitUtil.format(sb, backgroud, ",");
+ sb.append("}, source: {");
+ BitUtil.format(sb, source, ",");
+ sb.append("}, guide: {");
+ BitUtil.format(sb, traits, ",");
+ sb.append("}");
+ logger.finest(sb.toString());
+ }
+
+ if (focus == null)
+ return null;
+
+ OpenBitSet bound = new OpenBitSet();
+ if (source != null)
+ bound.or(source);
+ if (backgroud != null)
+ bound.or(backgroud);
+
+ tprism = traits;
+
+ OpenBitSet queue = new OpenBitSet();
+ queue.or(tprism);
+
+ // traverse the traits
+ OpenBitSet involved = new OpenBitSet();
+ while (true) {
+
+ long node = queue.nextSetBit(0);
+ if (node < 0)
+ break;
+
+ queue.clear(node);
+ involved.set(node);
+
+ OpenBitSet nodeFootprints = footprintsMap.get(node);
+ if (nodeFootprints == null) {
+ nodeFootprints = new OpenBitSet();
+ nodeFootprints.set(node);
+ footprintsMap.put(node, nodeFootprints);
+ }
+
+ long[] nextpoints = history.next(node);
+ if (nextpoints == null)
+ continue;
+
+ for (int j = 0; j < nextpoints.length; j++) {
+
+ long point = nextpoints[j];
+
+ OpenBitSet footprints = footprintsMap.get(point);
+ if (footprints == null) {
+ footprints = new OpenBitSet();
+ footprintsMap.put(point, footprints);
+ }
+
+ footprints.set(point);
+ footprints.or(nodeFootprints);
+
+ queue.set(point);
+ }
+ }
+
+ if (logger.isLoggable(Level.FINEST)) {
+ StringBuilder sb = new StringBuilder();
+ logger.finest(dumpStateDetail(sb).toString());
+ }
+
+ OpenBitSet selected = new OpenBitSet();
+
+ long numOfTraits = traits.cardinality();
+
+ queue = new OpenBitSet();
+ queue.or(focus);
+ involved = new OpenBitSet();
+ while (true) {
+
+ long node = queue.nextSetBit(0);
+ if (node < 0)
+ break;
+
+ queue.clear(node);
+ involved.set(node);
+
+ OpenBitSet nodeFootprints = footprintsMap.get(node);
+ if (nodeFootprints == null)
+ continue;
+
+ if (intersectionCount(bound, nodeFootprints) == 0
+ || intersectionCount(traits, nodeFootprints) == 0) {
+
+ continue;
+ }
+
+ long[] preivios = history.previous(node);
+ if (preivios == null)
+ continue;
+
+ boolean nosup = false;
+
+ for (int j = 0; j < preivios.length; j++) {
+
+ long point = preivios[j];
+
+ OpenBitSet footprints = footprintsMap.get(point);
+ if (footprints == null)
+ continue;
+
+ if (intersectionCount(bound, footprints) == 0)
+ continue;
+
+ if (intersectionCount(tprism, footprints) == numOfTraits) {
+
+ queue.set(point);
+ nosup = true;
+ }
+ }
+
+ if (!nosup) {
+ selected.set(node);
+ }
+ }
+
+ tspectrum = selected;
+
+ if (logger.isLoggable(Level.FINEST)) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("on traits {");
+ BitUtil.format(sb, tprism, ",");
+ sb.append("}, t-spectrum: {");
+ BitUtil.format(sb, tspectrum, ",");
+ sb.append("}");
logger.finest(sb.toString());
}
+
+ return tspectrum;
}

- private StringBuilder dumpStateDetail(StringBuilder sb) {
+ public OpenBitSet tcomplementary() {
+
+ if (logger.isLoggable(Level.FINEST)) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("background: {");
+ BitUtil.format(sb, backgroud, ",");
+ sb.append("}, source: {");
+ BitUtil.format(sb, source, ",");
+ sb.append("}, t-spectrum: {");
+ BitUtil.format(sb, tspectrum, ",");
+ sb.append("}");
+ logger.finest(sb.toString());
+ }
+
+ OpenBitSet bound = new OpenBitSet();
+ if (source != null)
+ bound.or(source);
+ if (backgroud != null)
+ bound.or(backgroud);
+
+
+ if (focus == null || focus.isEmpty())
+ return null;
+
+ // negative spectrum
+ OpenBitSet nselected = new OpenBitSet();
+ for (long node = focus.nextSetBit(0); node >= 0; node = focus
+ .nextSetBit(node + 1)) {
+
+ long[] preivios = history.previous(node);
+ if (preivios == null)
+ continue;
+
+ for (int j = 0; j < preivios.length; j++) {
+
+ long point = preivios[j];
+
+ if (tprism.get(point))
+ continue;
+
+ OpenBitSet footprints = footprintsMap.get(point);
+ if (footprints == null)
+ continue;
+
+ if (intersectionCount(bound, footprints) == 0)
+ continue;
+
+ if (tspectrum != null
+ && intersectionCount(tspectrum, footprints) > 0) {
+ continue;
+ }
+
+ nselected.set(point);
+ }
+ }
+
+ OpenBitSet min = new OpenBitSet();
+ minimumOfTraits(min, nselected);
+
+ if (logger.isLoggable(Level.FINEST)) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("t-spectrum complementary: {");
+ BitUtil.format(sb, min, ",");
+ sb.append("}");
+ logger.finest(sb.toString());
+ }
+
+ return min;
+ }
+
+ private void minimumOfTraits(OpenBitSet minimum, OpenBitSet nselected) {
+
+ if (nselected == null || nselected.isEmpty())
+ return;
+
+ long p = nselected.nextSetBit(0);
+ minimum.set(p);
+ for (p = nselected.nextSetBit(p + 1); p >= 0; p = nselected
+ .nextSetBit(p + 1)) {

- sb.append("Dumping the details of search\n");
- sb.append(" bound: {");
- BitUtil.format(sb, bound, ",");
- sb.append("}\n");
- sb.append(" part: {");
- BitUtil.format(sb, part, ",");
- sb.append("}\n");
- sb.append("supremum: {");
- BitUtil.format(sb, supremum, ",");
- sb.append("}\n");
- sb.append(" sliced: {");
- BitUtil.format(sb, sliced, ",");
- sb.append("}\n");
+ OpenBitSet fp1 = footprintsMap.get(p);
+ if (OpenBitSet.andNotCount(fp1, minimum) > 0) {
+ minimum.andNot(fp1);
+ minimum.set(p);
+ }
+ }
+ }
+
+ public void search() {
+
+ }
+
+ private StringBuilder dumpStateDetail(StringBuilder sb) {

sb.append("== Footprints: \n");
OpenBitSet points = new OpenBitSet();

Modified: trunk/procilege/src/main/java/merisis/traitspace/impl/TraitSpaceImpl.java
==============================================================================
--- trunk/procilege/src/main/java/merisis/traitspace/impl/TraitSpaceImpl.java (original)
+++ trunk/procilege/src/main/java/merisis/traitspace/impl/TraitSpaceImpl.java Sat Jun 9 11:26:55 2007
@@ -36,14 +36,18 @@
OpenBitSet hvbound = new OpenBitSet();
hvbound.or(ctx.objective);
if (!viewStack.isEmpty()) {
- hvbound.or(viewStack.peek().bound);
+ hvbound.or(viewStack.peek().background);
}

HistoryView hv = new HistoryView();
- hv.bound = hvbound;
+ hv.background = hvbound;

viewStack.push(hv);
-
+
+ SketchImpl sketch = ctx.sketch;
+ sketch.setBackground(hv.background);
+ sketch.setSource(null);
+
ctx.objective = null;
}

@@ -52,13 +56,11 @@
ProcessContext ctx = getProcessContext();

HistoryView hv = ctx.viewStack.peek();
- OpenBitSet pickup = new OpenBitSet();

- pickup.or(ctx.objective);
+ SketchImpl sketch = ctx.sketch;
+ sketch.setBackground(hv.background);
+ sketch.setSource(ctx.objective);
ctx.objective = null;
- pickup.or(hv.bound);
-
- hv.pickup = pickup;
}

public void autobeam() {
@@ -71,14 +73,16 @@
OpenBitSet hvbound = null;
for (int i = 0; i < viewStack.size()
&& (hvbound == null || hvbound.isEmpty()); i++)
- hvbound = viewStack.get(i).bound;
+ hvbound = viewStack.get(i).background;

HistoryView hv = new HistoryView();
- hv.bound = hvbound;
- hv.pickup = new OpenBitSet();
- hv.pickup.or(hvbound);
+ hv.background = hvbound;
viewStack.push(hv);

+ SketchImpl sketch = ctx.sketch;
+ sketch.setBackground(hv.background);
+ sketch.setSource(null);
+
if (logger.isLoggable(Level.FINEST)) {
StringBuilder sb = new StringBuilder();
sb.append("beamed view: {");
@@ -93,28 +97,19 @@

ProcessContext ctx = getProcessContext();
ctx.viewStack.pop();
+
+ SketchImpl sketch = ctx.sketch;
+ sketch.setBackground(ctx.viewStack.peek().background);
+ sketch.setSource(null);
}

public void focus() {

ProcessContext ctx = getProcessContext();

- OpenBitSet bound;
- HistoryView hv = ctx.viewStack.peek();
- if (hv.pickup == null) {
- bound = new OpenBitSet();
- bound.or(hv.bound);
- } else {
- bound = hv.pickup;
- }
-
SketchImpl sketch = ctx.sketch;
- sketch.setBoundPart(bound, ctx.objective);
- ctx.objective = null;
-
- OpenBitSet bs = sketch.focus();
-
- ctx.objective = bs;
+ sketch.setPart(ctx.objective);
+ ctx.objective = sketch.focus();
}

public void tprism() {
@@ -138,12 +133,6 @@
ctx.objective = ctx.sketch.historical().rollHistory((int) roll);
}

- public void clear() {
-
- ProcessContext ctx = getProcessContext();
- ctx.objective = null;
- }
-
public void give(long... dots) {

ProcessContext ctx = getProcessContext();
@@ -184,7 +173,7 @@

ProcessContext ctx = getProcessContext();

- OpenBitSet onto = ctx.viewStack.peek().bound;
+ OpenBitSet onto = ctx.viewStack.peek().background;

return BitUtil.toArray(onto);
}
@@ -197,7 +186,7 @@
processces.set(ctx);

HistoryView hv = new HistoryView();
- hv.bound = new OpenBitSet();
+ hv.background = new OpenBitSet();

ctx.viewStack.push(hv);
}
@@ -217,7 +206,7 @@
}
}

- OpenBitSet backgrounds = ctx.viewStack.peek().bound;
+ OpenBitSet backgrounds = ctx.viewStack.peek().background;
for (long bg = backgrounds.nextSetBit(0); bg >= 0; bg = backgrounds
.nextSetBit(bg + 1)) {

Added: trunk/procilege/src/test/java/merisis/traitspace/EntityHappen3Test.java
==============================================================================
--- (empty file)
+++ trunk/procilege/src/test/java/merisis/traitspace/EntityHappen3Test.java Sat Jun 9 11:26:55 2007
@@ -0,0 +1,133 @@
+package merisis.traitspace;
+
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+import merisis.contentcloud.ContentCloud;
+import merisis.sense.SenseMaker;
+import merisis.util.BitUtil;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.inject.Inject;
+
+public class EntityHappen3Test extends AbstractTraitSpaceTest {
+
+ @Inject
+ EntityHappen eh;
+
+ @Inject
+ ContentCloud cloud;
+
+ @Test
+ public void happed() {
+
+ Assert.assertEquals(1L, n("T0"));
+ Assert.assertEquals(2L, n("d1"));
+ Assert.assertEquals(3L, n("d2"));
+ Assert.assertEquals(4L, n("name"));
+ Assert.assertEquals(5L, n("qname"));
+
+ eh.ripple(ay(n("name")), QNameReaction.class);
+
+ mvm.give(n("T0"));
+ mvm.stepin();
+ try {
+
+ mvm.give(n("d1"));
+ mvm.stepin();
+ try {
+ eh.happen(ay(n("name")), "a1");
+ eh.happen(ay(n("name")), "b1");
+ } finally {
+ mvm.stepout();
+ }
+
+ mvm.give(n("d2"));
+ mvm.stepin();
+ try {
+ eh.happen(ay(n("name")), "a2");
+ } finally {
+ mvm.stepout();
+ }
+
+ dumpHistory(0, 40);
+
+ mvm.give(n("d2"));
+ mvm.stepin();
+ try {
+ Assert.assertEquals("a2", eh.retrieve(ay(n("name"))));
+ Assert.assertEquals("/root/a2", eh.retrieve(ay(n("qname"))));
+ } finally {
+ mvm.stepout();
+ }
+
+ mvm.give(n("d1"));
+ mvm.stepin();
+ try {
+ Assert.assertEquals("b1", eh.retrieve(ay(n("name"))));
+ Assert.assertEquals("/root/b1", eh.retrieve(ay(n("qname"))));
+ } finally {
+ mvm.stepout();
+ }
+
+ Assert.assertEquals("b1", eh.retrieve(ay(n("d1"), n("name"))));
+ Assert.assertEquals("/root/b1", eh
+ .retrieve(ay(n("d1"), n("qname"))));
+
+ Assert.assertEquals("a2", eh.retrieve(ay(n("d2"), n("name"))));
+ Assert.assertEquals("/root/a2", eh
+ .retrieve(ay(n("d2"), n("qname"))));
+ } finally {
+ mvm.stepout();
+ }
+
+ }
+
+}
+
+class QNameReaction implements HappenReaction {
+
+ @Inject
+ private Logger logger;
+
+ @Inject
+ private EntityHappen eh;
+
+ @Inject
+ private ContentCloud cloud;
+
+ @Inject
+ private SenseMaker smr;
+
+ public void happen(long[] points) {
+
+ logger.info("reaction: " + BitUtil.toString(points));
+
+ for (int i = 0; i < points.length; i++) {
+
+ long pt = points[i];
+ Object content = cloud.retrieve(pt);
+ if (content == null || !(content instanceof String)) {
+ logger.warning(String.format("illegal content: %s", content));
+ continue;
+ }
+
+ String qname = "/root/";
+ qname += ((String) content);
+
+ long[] ontos = new long[1];
+ ontos[0] = n("qname");
+ eh.happen(ontos, qname, pt);
+ }
+ }
+
+ public long n(String name) {
+
+ QName qn = new QName(EntityHappen3Test.class.getName(), name);
+ return smr.sense(qn);
+ }
+
+}

Modified: trunk/procilege/src/test/java/merisis/traitspace/Sketch1Test.java
==============================================================================
--- trunk/procilege/src/test/java/merisis/traitspace/Sketch1Test.java (original)
+++ trunk/procilege/src/test/java/merisis/traitspace/Sketch1Test.java Sat Jun 9 11:26:55 2007
@@ -44,6 +44,7 @@

mvm.give(1,3);
mvm.source();
+ mvm.give();
mvm.focus();
assertSetEquals(ay(3), mvm.read());

Modified: trunk/procilege/src/test/java/merisis/traitspace/Sketch4Test.java
==============================================================================
--- trunk/procilege/src/test/java/merisis/traitspace/Sketch4Test.java (original)
+++ trunk/procilege/src/test/java/merisis/traitspace/Sketch4Test.java Sat Jun 9 11:26:55 2007
@@ -86,22 +86,16 @@
mvm.source();
mvm.focus();
assertSetEquals(ay(12), mvm.read());
- mvm.roll(1);
- assertSetEquals(ay(11), mvm.read());

mvm.give(14);
mvm.source();
mvm.focus();
assertSetEquals(ay(12), mvm.read());
- mvm.roll(1);
- assertSetEquals(ay(13), mvm.read());

mvm.give(10,14);
mvm.source();
mvm.focus();
assertSetEquals(ay(12), mvm.read());
- mvm.roll(1);
- assertSetEquals(null, mvm.read());

mvm.give(10,14);
mvm.source();

Modified: trunk/procilege/src/test/java/merisis/traitspace/Sketch7Test.java
==============================================================================
--- trunk/procilege/src/test/java/merisis/traitspace/Sketch7Test.java (original)
+++ trunk/procilege/src/test/java/merisis/traitspace/Sketch7Test.java Sat Jun 9 11:26:55 2007
@@ -38,16 +38,7 @@
mvm.source();
mvm.give(11);
mvm.focus();
- mvm.roll(0);
assertSetEquals(ay(7, 9), mvm.read());
- mvm.roll(1);
- assertSetEquals(ay(5), mvm.read());
- mvm.roll(2);
- assertSetEquals(ay(6), mvm.read());
- mvm.roll(3);
- assertSetEquals(ay(1), mvm.read());
- mvm.roll(4);
- assertSetEquals(null, mvm.read());
}

@Test
@@ -85,14 +76,6 @@
mvm.give(11);
mvm.focus();
assertSetEquals(ay(7, 9), mvm.read());
- mvm.roll(1);
- assertSetEquals(ay(6), mvm.read());
- mvm.roll(2);
- assertSetEquals(ay(5), mvm.read());
- mvm.roll(3);
- assertSetEquals(ay(1), mvm.read());
- mvm.roll(4);
- assertSetEquals(null, mvm.read());
}

@Test

codesite...@google.com

unread,
Jun 9, 2007, 2:28:19 PM6/9/07
to procil...@googlegroups.com

codesite...@google.com

unread,
Jun 9, 2007, 2:29:33 PM6/9/07
to procil...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages