Esempio n. 1
0
    def __fetch_requests(self, task_entry):
        p = Pattern(task_entry, self.__getCurrentShell(task_entry), self.global_data)

        timeout = task_entry.get('timeout', 120)
        urls = p.convertPattern('url')
        s = requests.session()
        headers = task_entry.get('headers', [])
        task_entry['datas'] = []
        if not urls:
            return task_entry
        for url in urls:
            self.logger.info("fetching " + url)
            data = ""
            if not url:
                # do not fetch null url
                continue
            try:
                response = s.get(url, timeout=timeout, headers=headers)
                if 200 != response.status_code:
                    self.logger.error("fetch " + url + " failed with code " + (str)(response.status_code))
                data = response.text
            except:
                self.logger.error("fetch " + url + " failed in sockets")
            task_entry['datas'].append(data)
        return task_entry
Esempio n. 2
0
    def getPattern(self):

        pat = Pattern()
        
        for i in range(0, self.length):
            try:
                note = MIDI_Dict[self.GetCellValue(NOTE_ROW,i)]
            except KeyError, e:
                note = REST_NOTE
            
            if 'A' in self.GetCellValue(EFFECT_ROW, i):
                accent = True
            else:
                accent = False

            if 'S' in self.GetCellValue(EFFECT_ROW,i):
                slide = True
            else:
                slide = False

            if 'U' in self.GetCellValue(EFFECT_ROW, i):
                transpose = TRANSPOSE_UP
            elif 'D' in self.GetCellValue(EFFECT_ROW, i):
                transpose = TRANSPOSE_DOWN
            else:
                transpose = TRANSPOSE_NONE

            pat.appendNote(note, accent, slide, transpose)
Esempio n. 3
0
File: rule.py Progetto: qwert42/fos
class If:
    def __init__(self, predicate):
        if isinstance(predicate, str):
            self.predicate = Pattern(predicate)
        else:
            self.predicate = predicate
        self.predicate_assertion = True
        self.deduction = Pattern('')

    def is_(self, v):
        self.predicate_assertion = v
        return self

    def then(self, deduction):
        if isinstance(deduction, str):
            self.deduction = Pattern(deduction)
        else:
            self.deduction = deduction
        return self

    def deduct(self, input_):
        refs, successful = self.predicate.match(input_)
        if self.predicate_assertion and successful:
            return self.deduction.evaluate(refs)
        else:
            raise Paradox

    def __str__(self):
        return 'if %s then %s' % (self.predicate, self.deduction)
Esempio n. 4
0
File: rule.py Progetto: qwert42/fos
 def __init__(self, predicate):
     if isinstance(predicate, str):
         self.predicate = Pattern(predicate)
     else:
         self.predicate = predicate
     self.predicate_assertion = True
     self.deduction = Pattern('')
Esempio n. 5
0
 def export(self):
     """
     """
     logger.debug("Begin RSS Export:")
     db = CrawlDB()
     rep = Pattern()
     for pat in db.getPatterns():
         pid = pat["pid"]
         pattern = pat["pattern"]
         description = pat["name"]
         items = []
         for page in db.getPages("where pid=%d limit 10" % pid):
             items.append(self.rssitem % (page["url"],
                                          page["title"],
                                          "",
                                          pattern,
                                          "",
                                          page["url"],
                                          rep.sub(page["content"])))
         itemout = "\n".join(items)
         output = self.rssframe % (pattern,
                                   "http://hjbbs.com/bbs",
                                   description,
                                   "Learning English Tool",
                                   itemout)
         logger.debug("LET %d:\n%s\n" % (pid, output))
         # write out
         fp = open("%slet%d.xml" % (config.RSSDIR, pid), "w")
         fp.write(output.encode('utf8'))
         fp.close()
     logger.debug("End RSS Export.")
Esempio n. 6
0
    def __init__(self, filename):
        Pattern.__init__(self, filename)

        if self.n&1023 != 0:
            raise ValueError('Number of patterns must be a multiple of 1024.')

        self.patterns_gpu = cuda.mem_alloc(self.patterns.nbytes)
        cuda.memcpy_htod(self.patterns_gpu, self.patterns)

        self.input_gpu = cuda.mem_alloc(4*((40*8)+16))
        self.result_gpu = gpuarray.empty((40,self.n), dtype=numpy.float32, allocator=cuda.mem_alloc)
    def __init__(self, config, config_global):
        """Init pattern."""
        self.config_defaults = {
            'xxx': 0,
            "list": [
                [
                    1,
                    -1,
                    -1,
                    -1,
                    -1,
                    1,
                    -1,
                    -1,
                    -1,
                    -1,
                    1,
                    -1,
                    -1,
                    -1,
                    -1,
                    1
                ],
                [
                    0,
                    -1,
                    -1,
                    -1,
                    -1,
                    0,
                    -1,
                    -1,
                    -1,
                    -1,
                    0,
                    -1,
                    -1,
                    -1,
                    -1,
                    0
                ]
            ],
        }
        # python3 syntax
        # super().__init__()
        # python2 syntax
        # super(Pattern, self).__init__()
        # explicit call
        Pattern.__init__(self, config, config_global)

        # inits for this pattern
        self.strobe_state = False
Esempio n. 8
0
 def __fetch(self, task_entry):
     p = Pattern(task_entry, self.__getCurrentShell(task_entry), self.config_data)
     urls = p.convertPattern('url')
     s = requests.session()
     task_entry['datas'] = []
     for url in urls:
         self.logger.info("fetching " + url)
         if "" == url:
             # do not fetch null url
             continue
         response = s.get(url)
         if 200 != response.status_code:
             self.logger.error("fetch " + url + " failed with code" + response.status_code)
         data = response.text
         task_entry['datas'].append(data)
     return task_entry
Esempio n. 9
0
def loadPatternsFromFile(f):

	# load patterns from file f
	# return: a list of patterns
	
	patterns = list();
	xy = False;
	p = 0;

	ifile = open(f);
	for line in ifile:
		if(line.startswith("===")):
			if p!=0:
				patterns.append(p)
			p = Pattern();
			xy = True;
			continue;
		elements = line.strip().split("\t");

		if xy == True:
			xy = False;
			p.x = elements[0];
			p.y = elements[1];

		v1 = p.g.add_node(elements[0],l=int(elements[1]));
		for i in range(2,len(elements)):
			p.g.add_edge(elements[0],elements[i]);
		# g.elements[0]
		p.covered.add(p.id);

	if(p!=0):
		patterns.append(p);

	if(debug):
		for p in patterns:
			# printG(g,1,0);
			print p.id;
			print p.g.nodes(data=True)
			print p.g.edges();
	

	return patterns;
Esempio n. 10
0
    def __fetch_webkit(self, task_entry):
        p = Pattern(task_entry, self.__getCurrentShell(task_entry), self.global_data)

        import cwebbrowser

        task_entry['datas'] = []

        urls = p.convertPattern('url')
        timeout = task_entry.get('timeout', 120)
        delay = task_entry.get('delay', 0)

        for url in urls:
            self.logger.info("fetching " + url)
            data = ""
            if not url:
                # do not fetch null url
                continue
            browser = cwebbrowser.CWebBrowser()
            browser.setHeaders(task_entry.get('headers', []))
            #browser.show();
            try:
                browser.load(url=url, load_timeout=timeout, delay=delay)
            except cwebbrowser.Timeout:
                self.logger.error("fetch " + url + " timeout ")
            except  Exception, exception:
                self.logger.error("fetch " + url + " error ")
                print "Exception message:", exception

            else:
                html = browser.html()
                if html:
                    html = html.encode('utf-8')
                    data = html
                else:
                    self.logger.error("fetch " + url + " failed with no response")
            task_entry['datas'].append(data)

            browser.close()
Esempio n. 11
0
File: analysis.py Progetto: ttm/pyo
 def __init__(self, input, length=0.05, gain=0.67):
     PyoObject.__init__(self)
     self.points = None
     self.viewFrame = None
     self._input = input
     self._length = length
     self._gain = gain
     self._width = 500
     self._height = 400
     self._in_fader = InputFader(input)
     in_fader, lmax = convertArgsToLists(self._in_fader)
     self._base_objs = [Scope_base(wrap(in_fader,i), length) for i in range(lmax)]
     self.view()
     self._timer = Pattern(self.refreshView, length).play()
Esempio n. 12
0
 def test_refracted_color_with_refracted_ray(self):
     w = World.default_world()
     a = w.objects[0]
     a.material.ambient = 1.0
     a.material.pattern = Pattern.test_pattern()
     b = w.objects[1]
     b.material.transparency = 1.0
     b.material.refractive_index = 1.5
     r = Ray(Point(0, 0, 0.1), Vector(0, 1, 0))
     xs = Intersection.intersections(Intersection(-0.9899, a),
                                     Intersection(-0.4899, b),
                                     Intersection(0.4899, b),
                                     Intersection(0.9899, a))
     comps = Computations.prepare_computations(xs[2], r, xs)
     c = World.refracted_color(w, comps, 5)
     self.assertEqual(c, Color(0, 0.99888, 0.04725))
Esempio n. 13
0
 def __init__(self, input, function=None, mul=1, add=0):
     PyoObject.__init__(self, mul, add)
     self._input = input
     if callable(function):
         self._function = getWeakMethodRef(function)
     else:
         self._function = None
     self._in_fader = InputFader(input)
     in_fader, mul, add, lmax = convertArgsToLists(self._in_fader, mul, add)
     self._base_objs = [
         PeakAmp_base(wrap(in_fader, i), wrap(mul, i), wrap(add, i))
         for i in range(lmax)
     ]
     sr = self.getSamplingRate()
     bs = self.getBufferSize()
     self._timer = Pattern(self._buildList, bs / sr).play()
Esempio n. 14
0
 def __init__(
         self,
         uri,
         path=None,
         revision=None,
         remote=None,  # pylint: disable=W0613
         pattern=None,
         *args,
         **kws):
     self.uri = self._safepath(uri)
     self.path = self._safepath(path)
     self.revision = revision
     self.remote = remote
     self.source = kws.get('source') or remote
     self.pattern = pattern or Pattern()
     self.args = args
     self.kws = kws
Esempio n. 15
0
    def sendReadPatternMessage(self, bank, loc):
        self.s.flushInput()
        self.sendBasicPacket(READ_PATTERN_MSG, content=chr(bank) + chr(loc))

        packet = self.getBasicPacket()
        if packet.isCorrect:
            packet.printMe()
        else:
            packet.printMe()
            print 'Bad packet!'

        if packet.isCorrect and packet.messageType() == X0X_PATT_MSG:
            pat = Pattern(packet.content())
            return pat
        else:
            print 'Error: Received a bad pattern.'
            raise BadPacketException('Received a bad pattern.')
def siatech(d):
    d = Dataset.sort_ascending(d)
    # Map of difference vector, index list pairs.
    mtp_map = {}

    # Compute the difference vectors between points and add both
    # the starting and ending index as pair to the lists corresponding to the
    # difference vector.
    for i in range(len(d)):
        for j in range(i + 1, len(d)):
            diff = d[j] - d[i]
            if diff in mtp_map:
                mtp_map[diff].append((i, j))
            else:
                mtp_map[diff] = [(i, j)]

    tecs = []
    handled_patterns = set()

    for diff_vec in mtp_map:
        pattern = []
        pattern_indices = []
        mtp = mtp_map[diff_vec]

        for index_pair in mtp:
            pattern_indices.append(index_pair[0])
            pattern.append(d[index_pair[0]])

        vectorized_pattern = Pattern(vec(pattern))

        if vectorized_pattern not in handled_patterns:
            translators = []
            if len(pattern) == 1:
                for point in d:
                    translators.append(point - pattern[0])
            else:
                translators = find_translators_h(pattern, vectorized_pattern,
                                                 mtp_map, d)

            tecs.append(TEC(pattern, pattern_indices, translators))
            handled_patterns.add(vectorized_pattern)

    return tecs
Esempio n. 17
0
    def respond_to_key(self, k):
        GestureClassifier.respond_to_key(self, k)
        if k == 'w':
            if self.recording:
                self.recording = False

                print "STOPPED RECORDING"
                name = raw_input("Enter a name for this gesture: ")
                self.patterns.append(Pattern(name, self.pattern_points))
                #print self.patterns[-1].normalize()
                self.reset()
            else:
                print "STARTED RECORDING"
                self.recording = True
                self.reset()
        elif k == 's':
            if len(self.patterns) > 0:
                self.write_to_file()
        return
 def load_from(path: str):
     collection = PatternCollection()
     with open(path, 'r', encoding='utf8') as csv:
         next(csv)
         for line in csv:
             line = line.strip()
             parts = line.split(';')
             tool = None
             sentiment = None
             for t in Tool:
                 if parts[0] == t.name:
                     tool = t
                     break
             for s in Sentiment:
                 if parts[1] == s.name:
                     sentiment = s
                     break
             change = parts[2]
             collection.append(Pattern(sentiment, tool, '', change))
     return collection
Esempio n. 19
0
class PatternListener(liblo.ServerThread):
    def __init__(self, address=8765):
        liblo.ServerThread.__init__(self, address)
        self.pattern = Pattern()

    @liblo.make_method('/pattern/set', 'ii')
    def set_callback(self, path, args):
        track, step = args
        self.pattern.set_step(track, step)

    @liblo.make_method('/pattern/clear', 'ii')
    def clear_callback(self, path, args):
        track, step = args
        self.pattern.clear_step(track, step)

    @liblo.make_method('/pattern/mute', 'i')
    def mute_callback(self, path, track):
        self.pattern.mute(track)

    @liblo.make_method('/pattern/unmute', 'i')
    def unmute_callback(self, path, track):
        self.pattern.unmute(track)
Esempio n. 20
0
class PatternListener(liblo.ServerThread):
    def __init__(self, address=8765):
        liblo.ServerThread.__init__(self, address)
        self.pattern = Pattern()

    @liblo.make_method('/pattern/set', 'ii')
    def set_callback(self, path, args):
        track, step = args
        self.pattern.set_step(track, step)

    @liblo.make_method('/pattern/clear', 'ii')
    def clear_callback(self, path, args):
        track, step = args
        self.pattern.clear_step(track, step)

    @liblo.make_method('/pattern/mute', 'i')
    def mute_callback(self, path, track):
        self.pattern.mute(track)

    @liblo.make_method('/pattern/unmute', 'i')
    def unmute_callback(self, path, track):
        self.pattern.unmute(track)
Esempio n. 21
0
File: analysis.py Progetto: ttm/pyo
 def __init__(self, input, size=1024, wintype=2, function=None):
     PyoObject.__init__(self)
     self.points = None
     self.viewFrame = None
     self._input = input
     self._size = size
     self._wintype = wintype
     self._function = getWeakMethodRef(function)
     self._fscaling = 0
     self._mscaling = 1
     self._lowbound = 0
     self._highbound = 0.5
     self._width = 500
     self._height = 400
     self._gain = 1
     self._in_fader = InputFader(input)
     in_fader, size, wintype, lmax = convertArgsToLists(self._in_fader, size, wintype)
     self._base_objs = [Spectrum_base(wrap(in_fader,i), wrap(size,i), wrap(wintype,i)) for i in range(lmax)]
     if function == None:
         self.view()
     self._timer = Pattern(self.refreshView, 0.05).play()
Esempio n. 22
0
 def read_bytes(self, data):
     try:
         self.name = data[0:20].rstrip(b'\0').decode()
     except UnicodeDecodeError:
         self.name = 'invalid'
     for offset in range(20, 950, 30):
         sample = Sample(data[offset:offset + 30])
         self.samples.append(sample)
         if sample.name:
             self.vanity += '\n' + sample.name
     length = data[950]
     self.positions = [byte for byte in data[952:1080]][:length]
     self.mk = data[1080:1084]
     num_patterns = max(self.positions) + 1
     dex = 1024 * num_patterns + 1084
     for offset in range(1084, dex, 1024):
         self.patterns.append(Pattern(data[offset:offset + 1024]))
     for sample in self.samples[1:]:
         dex2 = dex + sample.length
         sample.wave = data[dex:dex2]
         dex = dex2
Esempio n. 23
0
def wait(image_name, timeout=None, precision=None, in_region=None):
    """Wait for a Pattern or image to appear

    :param image_name: String or Pattern
    :param timeout: Number as maximum waiting time in seconds.
    :param precision: Matching similarity
    :param in_region: Region object in order to minimize the area
    :return: True if found
    """
    if isinstance(image_name, str) and is_ocr_text(image_name):
        a_match = text_search_by(image_name, True, in_region)
        if a_match is not None:
            return True
        else:
            raise FindError('Unable to find text %s' % image_name)

    elif isinstance(image_name, str) or isinstance(image_name, Pattern):
        if timeout is None:
            timeout = Settings.AutoWaitTimeout

        if precision is None:
            precision = Settings.MinSimilarity

        try:
            pattern = Pattern(image_name)
        except Exception:
            pattern = image_name

        image_found = positive_image_search(pattern, timeout, precision,
                                            in_region)

        if image_found is not None:
            return True
        else:
            raise FindError('Unable to find image %s' % image_name)

    else:
        raise ValueError(INVALID_GENERIC_INPUT)
Esempio n. 24
0
def _general_click(where=None,
                   clicks=None,
                   duration=None,
                   in_region=None,
                   button=None):
    """General Mouse Click

    :param where: Location , image name or Pattern
    :param clicks: Number of mouse clicks
    :param duration: speed of hovering from current location to target
    :param in_region: Region object in order to minimize the area
    :param button: Mouse button clicked (can be left, right, middle, 1, 2, 3)
    :return: None
    """

    if duration is None:
        duration = Settings.MoveMouseDelay

    if isinstance(where, str) and is_ocr_text(where):
        a_match = text_search_by(where, True, in_region)
        if a_match is not None:
            click_location = Location(a_match['x'] + a_match['width'] / 2,
                                      a_match['y'] + a_match['height'] / 2)
            _click_at(click_location, clicks, duration, button)

    elif isinstance(where, Location):
        _click_at(where, clicks, duration, button)

    elif isinstance(where, str) or isinstance(where, Pattern):
        try:
            pattern = Pattern(where)
        except Exception:
            pattern = where

        _click_pattern(pattern, clicks, duration, in_region, button)

    else:
        raise ValueError(INVALID_GENERIC_INPUT)
    def __add_pattern_to_trade_candidate_list_for_buy_trigger__(
            self, pattern: Pattern, buy_trigger: str, trade_strategies: list):
        best_strategy = self.__get_best_trade_strategy_for_pattern__(
            buy_trigger, pattern, trade_strategies)
        if best_strategy == '':
            key = self.__get_key_for_black_buy_pattern_id_readable_list(
                pattern, buy_trigger)
            self.__add_to_black_buy_pattern_id_readable_list__(
                key, BLR.NO_BEST_STRATEGY)
            return

        # we want to have limit fix strategy for all trades - for statistics reasons
        trade_strategy_list = [best_strategy
                               ] if best_strategy == TSTR.LIMIT_FIX else [
                                   best_strategy, TSTR.LIMIT_FIX
                               ]
        for trade_strategy in trade_strategy_list:
            key_buy_and_strategy = self.__get_key_for_black_buy_and_strategy_pattern_id_readable_list(
                pattern, buy_trigger, trade_strategy)

            if key_buy_and_strategy in self._black_buy_and_strategy_pattern_id_readable_list:
                pass
                # print('Already in black_buy_trigger_trade_strategy_pattern_id_list: {}'.format(key_buy_and_strategy))
            else:
                print('Add_to_candidate_list: Checking trade strategy: {}'.
                      format(key_buy_and_strategy))
                if pattern.are_conditions_for_trade_strategy_fulfilled(
                        trade_strategy):
                    trade_api = PatternTradeApi(pattern, buy_trigger,
                                                trade_strategy)
                    trade_api.exchange_config = self.exchange_config
                    trade_api.last_price_mean_aggregation = self.__get_optimal_last_price_mean_aggregation__(
                        pattern)
                    self.__add_trade_candidate_entry_to_ticker_id_dict__(
                        TradeCandidate(PatternTrade(trade_api)))
                else:
                    self.__add_to_black_buy_strategy_pattern_id_readable_list__(
                        key_buy_and_strategy, BLR.TRADE_STRATEGY_CONDITIONS)
Esempio n. 26
0
def waitVanish(image_name, timeout=None, precision=None, in_region=None):
    """Wait until a Pattern or image disappears

    :param image_name: Image, Pattern or string
    :param timeout:  Number as maximum waiting time in seconds.
    :param precision: Matching similarity
    :param in_region: Region object in order to minimize the area
    :return: True if vanished
    """

    if timeout is None:
        timeout = Settings.AutoWaitTimeout

    if precision is None:
        precision = Settings.MinSimilarity

    pattern = Pattern(image_name)
    image_found = negative_image_search(pattern, timeout, precision, in_region)

    if image_found is not None:
        return True
    else:
        raise FindError('%s did not vanish' % image_name)
Esempio n. 27
0
def extract_patterns_unitary(ld_graph: rdflib.Graph):
    """Extracts from the linked data graph the patterns of length 1 together
    with the instance nodes that are involved in such pattern.
    The information for each semantic relation is represented in a Pattern
    object.

    See the Pattern class docs for more details about the information handling.

    Parameters
    ----------
    ld_graph: rdflib.Graph
        The graph object containing the triples of the Linked data

    Returns
    -------
    list
        List of patterns (class Pattern) of length 1
    """

    qres = ld_graph.query(queries.length_1_triples)

    P1 = dict()
    i = 0
    for row in qres:
        (x, c1, p, y, c2) = row
        semantic_relation = (str(c1), str(p), str(c2))
        if semantic_relation not in P1.keys():
            # Create pattern graph and Pattern object
            new_p = Pattern(i, 1, 0)
            P1[semantic_relation] = new_p
            i += 1
        pattern = P1[semantic_relation]
        pattern.add_relation(c1, c2, p)
        pattern.add_relation_instance(c1, x, c2, y, p)
        pattern.frequency += 1
    #pickle.dump(P1, open('P1.pkl', 'wb'), protocol=pickle.HIGHEST_PROTOCOL)
    return list(P1.values())
Esempio n. 28
0
def write_dists(n, nr, group_name):
    p = Pattern(n)
    p.group(group_name)
    p.to_fractional_coordinate()
    lattice_vectors = np.array([p.a1, p.a2])
    center_cell_fracts = np.mod(p.xys + .5, 1) - .5
    rmax = np.max([
        np.linalg.norm(np.dot(ij, lattice_vectors))
        for ij in product((-1, 1), repeat=2)
    ])

    num_layer = 36
    x = range(-num_layer, num_layer + 1)
    I, J = np.meshgrid(x, x)
    I, J = I.flatten(), J.flatten()
    xys = I[:, None] * p.a1 + J[:, None] * p.a2
    mask = xys[:, 0]**2 + xys[:, 1]**2 <= rmax * rmax * 4
    I, J = I[mask], J[mask]
    image_cell_fracts = np.concatenate(
        [center_cell_fracts + np.array(ij) for ij in zip(I, J)])

    center_cell_carts = np.array(
        [np.dot(fract, lattice_vectors) for fract in center_cell_fracts])
    image_cell_carts = np.array(
        [np.dot(fract, lattice_vectors) for fract in image_cell_fracts])

    dists = cdist(center_cell_carts, image_cell_carts)
    dists = dists[np.logical_and(dists > 0, dists <= rmax)]

    bins = np.linspace(0, rmax, nr)
    hist = np.histogram(dists, bins)
    counts = hist[0]

    rho = (len(center_cell_carts) / np.linalg.norm(np.cross(p.a1, p.a2)))
    return counts / counts.sum() / rho / (2 * np.pi * bins[1:]) / (bins[1] -
                                                                   bins[0])
Esempio n. 29
0
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import regex

from collections import Counter
from pattern import Pattern, raw_patterns, categories, HSC_RANGE_8, HSC_GROUP_8, HSC_GROUP_8_NC
import pprint

## -----------------------------------------------------------------------------
## Globals
## -----------------------------------------------------------------------------

search_patterns = {}
for name, category in categories.items():
    search_patterns[name] = Pattern(name, raw_patterns[name], category)

## -----------------------------------------------------------------------------
## Class Definition
## -----------------------------------------------------------------------------


class RoO:
    """Represent the Rules of Origin (with relevant methods) of a single FTA.

    Methods:
      plot_chapter_restrictions():
        Create a line plot of cumulative roo_1 (y-axis) vs HS chapter (x-axis).
      scatter_plot():
        Create a scatter plot of roo_1 (y-axis) vs HS chapter (x-axis).
      restrictions_table():
Esempio n. 30
0
	print "recheck with bigQ: " , bigQ;
	while len(bigQ)!=0:
		p = bigQ.pop()
		print "p.id=",p.id,"p.x,p.y",p.x, p.y
		if len(shouldHaveAll.difference(p.covered))!=0:
			# not contain all required nodes
			print "discards p id=",p.id,"since don't covered all should cover."
			pass;

		else:
			#generate several Q'
			for e2y in p.g.out_edges():
				if node_match(p.g.node[e2y[1]],p.g.node[p.y]):
					# edges every x->y
					r = Pattern();
					r.g = p.g.copy();
					r.x = p.x;
					r.y = e2y[1];
					print r.x,"---",r.y
					print "edgesize,b4",len(r.g.edges()),r.g.degree(r.y)
					r.g.remove_edge(e2y[0],e2y[1]);
					print "edgesize,aft",len(r.g.edges()),r.g.degree(r.y)
					if r.g.degree(r.y)==0:
						print "remove y", r.y
						r.g.remove_node(r.y); 
					
					# print float(suppThreshold)/confThreshold;
					if computeSupport(baseG,r) <= float(suppThreshold)/confThreshold:
						# WARN: r will be 0;
						sigma.append(r);
Esempio n. 31
0
            m1_int_sel_gpot, m1_int_sel_spike,
            np.zeros(N1_gpot, dtype=np.double),
            np.zeros(N1_spike, dtype=int),
            ['interface', 'io', 'type'],
            CTRL_TAG, GPOT_TAG, SPIKE_TAG, time_sync=True)
    m2_id = 'm2   '
    man.add(MyModule, m2_id, m2_int_sel, m2_int_sel_in, m2_int_sel_out,
            m2_int_sel_gpot, m2_int_sel_spike,
            np.zeros(N2_gpot, dtype=np.double),
            np.zeros(N2_spike, dtype=int),
            ['interface', 'io', 'type'],
            CTRL_TAG, GPOT_TAG, SPIKE_TAG, time_sync=True)

    # Make sure that all ports in the patterns' interfaces are set so 
    # that they match those of the modules:
    pat12 = Pattern(m1_int_sel, m2_int_sel)
    pat12.interface[m1_int_sel_out_gpot] = [0, 'in', 'gpot']
    pat12.interface[m1_int_sel_in_gpot] = [0, 'out', 'gpot']
    pat12.interface[m1_int_sel_out_spike] = [0, 'in', 'spike']
    pat12.interface[m1_int_sel_in_spike] = [0, 'out', 'spike']
    pat12.interface[m2_int_sel_in_gpot] = [1, 'out', 'gpot']
    pat12.interface[m2_int_sel_out_gpot] = [1, 'in', 'gpot']
    pat12.interface[m2_int_sel_in_spike] = [1, 'out', 'spike']
    pat12.interface[m2_int_sel_out_spike] = [1, 'in', 'spike']
    pat12['/a/out/gpot0', '/b/in/gpot0'] = 1
    pat12['/a/out/gpot1', '/b/in/gpot1'] = 1
    pat12['/b/out/gpot0', '/a/in/gpot0'] = 1
    pat12['/b/out/gpot1', '/a/in/gpot1'] = 1
    pat12['/a/out/spike0', '/b/in/spike0'] = 1
    pat12['/a/out/spike1', '/b/in/spike1'] = 1
    pat12['/b/out/spike0', '/a/in/spike0'] = 1
 def get_pattern_center_shape(pattern: Pattern):
     ellipse_height = pattern.get_center_shape_height()
     ellipse_width = pattern.get_center_shape_width()
     xy_center = PlotterInterface.get_xy_from_timestamp_to_date_number(pattern.xy_center)
     return Ellipse(np.array(xy_center), ellipse_width, ellipse_height)
Esempio n. 33
0
File: rule.py Progetto: fnmdx111/fos
 def then(self, deduction):
     if isinstance(deduction, str):
         self.deduction = Pattern(deduction)
     else:
         self.deduction = deduction
     return self
Esempio n. 34
0
        m2_int_sel_in,
        m2_int_sel_out,
        m2_int_sel_gpot,
        m2_int_sel_spike,
        np.zeros(N2_gpot, dtype=np.double),
        np.zeros(N2_spike, dtype=int),
        ["interface", "io", "type"],
        CTRL_TAG,
        GPOT_TAG,
        SPIKE_TAG,
        time_sync=True,
    )

    # Make sure that all ports in the patterns' interfaces are set so
    # that they match those of the modules:
    pat12 = Pattern(m1_int_sel, m2_int_sel)
    pat12.interface[m1_int_sel_out_gpot] = [0, "in", "gpot"]
    pat12.interface[m1_int_sel_in_gpot] = [0, "out", "gpot"]
    pat12.interface[m1_int_sel_out_spike] = [0, "in", "spike"]
    pat12.interface[m1_int_sel_in_spike] = [0, "out", "spike"]
    pat12.interface[m2_int_sel_in_gpot] = [1, "out", "gpot"]
    pat12.interface[m2_int_sel_out_gpot] = [1, "in", "gpot"]
    pat12.interface[m2_int_sel_in_spike] = [1, "out", "spike"]
    pat12.interface[m2_int_sel_out_spike] = [1, "in", "spike"]
    pat12["/a/out/gpot0", "/b/in/gpot0"] = 1
    pat12["/a/out/gpot1", "/b/in/gpot1"] = 1
    pat12["/b/out/gpot0", "/a/in/gpot0"] = 1
    pat12["/b/out/gpot1", "/a/in/gpot1"] = 1
    pat12["/a/out/spike0", "/b/in/spike0"] = 1
    pat12["/a/out/spike1", "/b/in/spike1"] = 1
    pat12["/b/out/spike0", "/a/in/spike0"] = 1
Esempio n. 35
0
 def get_pattern(self):
     pattern = Pattern(self._pattern_id)
     pattern.set_controller(self._controller)
     return pattern
Esempio n. 36
0
 def __init__(self, address=8765):
     liblo.ServerThread.__init__(self, address)
     self.pattern = Pattern()
Esempio n. 37
0
class Spectrum(PyoObject):
    """
    Spectrum analyzer and display.

    Spectrum measures the magnitude of an input signal versus frequency
    within a user defined range. It can show both magnitude and frequency
    on linear or logarithmic scale.

    :Parent: :py:class:`PyoObject`

    :Args:

        input : PyoObject
            Input signal to process.
        size : int {pow-of-two > 4}, optional
            FFT size. Must be a power of two greater than 4.
            The FFT size is the number of samples used in each
            analysis frame. Defaults to 1024.
        wintype : int, optional
            Shape of the envelope used to filter each input frame.
            Possible shapes are :
                0. rectangular (no windowing)
                1. Hamming
                2. Hanning
                3. Bartlett (triangular)
                4. Blackman 3-term
                5. Blackman-Harris 4-term
                6. Blackman-Harris 7-term
                7. Tuckey (alpha = 0.66)
                8. Sine (half-sine window)
        function : python callable, optional
            If set, this function will be called with magnitudes (as
            list of lists, one list per channel). Useful if someone
            wants to save the analysis data into a text file.
            Defaults to None.

    .. note::

        Spectrum has no `out` method.

        Spectrum has no `mul` and `add` attributes.

    >>> s = Server().boot()
    >>> s.start()
    >>> a = SuperSaw(freq=[500,750], detune=0.6, bal=0.7, mul=0.5).out()
    >>> spec = Spectrum(a, size=1024)

    """
    def __init__(self, input, size=1024, wintype=2, function=None):
        pyoArgsAssert(self, "oiiC", input, size, wintype, function)
        PyoObject.__init__(self)
        self.points = None
        self.viewFrame = None
        self._input = input
        self._size = size
        self._wintype = wintype
        self._function = getWeakMethodRef(function)
        self._fscaling = 0
        self._mscaling = 1
        self._lowbound = 0
        self._highbound = 0.5
        self._width = 500
        self._height = 400
        self._gain = 1
        self._in_fader = InputFader(input)
        in_fader, size, wintype, lmax = convertArgsToLists(self._in_fader, size, wintype)
        self._base_objs = [Spectrum_base(wrap(in_fader,i), wrap(size,i), wrap(wintype,i)) for i in range(lmax)]
        self._timer = Pattern(self.refreshView, 0.05).play()
        if function == None:
            self.view()

    def setInput(self, x, fadetime=0.05):
        """
        Replace the `input` attribute.

        :Args:

            x : PyoObject
                New signal to process.
            fadetime : float, optional
                Crossfade time between old and new input. Default to 0.05.

        """
        pyoArgsAssert(self, "oN", x, fadetime)
        self._input = x
        self._in_fader.setInput(x, fadetime)

    def setSize(self, x):
        """
        Replace the `size` attribute.

        :Args:

            x : int
                new `size` attribute.

        """
        pyoArgsAssert(self, "i", x)
        self._size = x
        x, lmax = convertArgsToLists(x)
        [obj.setSize(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setWinType(self, x):
        """
        Replace the `wintype` attribute.

        :Args:

            x : int
                new `wintype` attribute.

        """
        pyoArgsAssert(self, "i", x)
        self._wintype = x
        x, lmax = convertArgsToLists(x)
        [obj.setWinType(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setFunction(self, function):
        """
        Sets the function to be called to retrieve the analysis data.

        :Args:

            function : python callable
                The function called by the internal timer to retrieve the
                analysis data. The function must be created with one argument
                and will receive the data as a list of lists (one list per channel).

        """
        pyoArgsAssert(self, "C", function)
        self._function = getWeakMethodRef(function)

    def poll(self, active):
        """
        Turns on and off the analysis polling.

        :Args:

            active : boolean
                If True, starts the analysis polling, False to stop it.
                defaults to True.

        """
        pyoArgsAssert(self, "B", active)
        if active:
            self._timer.play()
        else:
            self._timer.stop()

    def polltime(self, time):
        """
        Sets the polling time in seconds.

        :Args:

            time : float
                Adjusts the frequency of the internal timer used to
                retrieve the current analysis frame. defaults to 0.05.

        """
        pyoArgsAssert(self, "N", time)
        self._timer.time = time

    def setLowFreq(self, x):
        """
        Sets the lower frequency, in Hz, returned by the analysis.

        :Args:

            x : float
                New low frequency in Hz. Adjusts the `lowbound` attribute, as `x / sr`.

        """
        pyoArgsAssert(self, "n", x)
        x /= self.getServer().getSamplingRate()
        self._lowbound = x
        x, lmax = convertArgsToLists(x)
        tmp = [obj.setLowbound(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setHighFreq(self, x):
        """
        Sets the higher frequency, in Hz, returned by the analysis.

        :Args:

            x : float
                New high frequency in Hz. Adjusts the `highbound` attribute, as `x / sr`.

        """
        pyoArgsAssert(self, "n", x)
        x /= self.getServer().getSamplingRate()
        self._highbound = x
        x, lmax = convertArgsToLists(x)
        tmp = [obj.setHighbound(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setLowbound(self, x):
        """
        Sets the lower frequency, as multiplier of sr, returned by the analysis.

        Returns the real low frequency en Hz.

        :Args:

            x : float {0 <= x <= 0.5}
                new `lowbound` attribute.

        """
        pyoArgsAssert(self, "n", x)
        self._lowbound = x
        x, lmax = convertArgsToLists(x)
        tmp = [obj.setLowbound(wrap(x,i)) for i, obj in enumerate(self._base_objs)]
        return tmp[0]

    def setHighbound(self, x):
        """
        Sets the higher frequency, as multiplier of sr, returned by the analysis.

        Returns the real high frequency en Hz.

        :Args:

            x : float {0 <= x <= 0.5}
                new `highbound` attribute.

        """
        pyoArgsAssert(self, "n", x)
        self._highbound = x
        x, lmax = convertArgsToLists(x)
        tmp = [obj.setHighbound(wrap(x,i)) for i, obj in enumerate(self._base_objs)]
        return tmp[0]

    def getLowfreq(self):
        """
        Returns the current lower frequency, in Hz, used by the analysis.

        """

        return self._base_objs[0].getLowfreq()

    def getHighfreq(self):
        """
        Returns the current higher frequency, in Hz, used by the analysis.

        """
        return self._base_objs[0].getHighfreq()

    def setWidth(self, x):
        """
        Sets the width, in pixels, of the current display.

        Used internally to build the list of points to draw.

        :Args:

            x : int
                new `width` attribute.

        """
        pyoArgsAssert(self, "i", x)
        self._width = x
        x, lmax = convertArgsToLists(x)
        [obj.setWidth(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setHeight(self, x):
        """
        Sets the height, in pixels, of the current display.

        Used internally to build the list of points to draw.

        :Args:

            x : int
                new `height` attribute.

        """
        pyoArgsAssert(self, "i", x)
        self._height = x
        x, lmax = convertArgsToLists(x)
        [obj.setHeight(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setFscaling(self, x):
        """
        Sets the frequency display to linear or logarithmic.

        :Args:

            x : boolean
                If True, the frequency display is logarithmic. False turns
                it back to linear. Defaults to False.

        """
        pyoArgsAssert(self, "b", x)
        self._fscaling = x
        x, lmax = convertArgsToLists(x)
        [obj.setFscaling(wrap(x,i)) for i, obj in enumerate(self._base_objs)]
        if self.viewFrame != None:
            self.viewFrame.setFscaling(self._fscaling)

    def setMscaling(self, x):
        """
        Sets the magnitude display to linear or logarithmic.

        :Args:

            x : boolean
                If True, the magnitude display is logarithmic (which means in dB).
                False turns it back to linear. Defaults to True.

        """
        pyoArgsAssert(self, "b", x)
        self._mscaling = x
        x, lmax = convertArgsToLists(x)
        [obj.setMscaling(wrap(x,i)) for i, obj in enumerate(self._base_objs)]
        if self.viewFrame != None:
            self.viewFrame.setMscaling(self._mscaling)

    def getFscaling(self):
        """
        Returns the scaling of the frequency display.

        Returns True for logarithmic or False for linear.

        """
        return self._fscaling

    def getMscaling(self):
        """
        Returns the scaling of the magnitude display.

        Returns True for logarithmic or False for linear.

        """
        return self._mscaling

    def setGain(self, x):
        """
        Set the gain of the analysis data. For drawing purpose.

        :Args:

            x : float
                new `gain` attribute, as linear values.

        """
        pyoArgsAssert(self, "n", x)
        self._gain = x
        x, lmax = convertArgsToLists(x)
        [obj.setGain(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def view(self, title="Spectrum", wxnoserver=False):
        """
        Opens a window showing the result of the analysis.

        :Args:

            title : string, optional
                Window title. Defaults to "Spectrum".
            wxnoserver : boolean, optional
                With wxPython graphical toolkit, if True, tells the
                interpreter that there will be no server window.

        If `wxnoserver` is set to True, the interpreter will not wait for
        the server GUI before showing the controller window.

        """
        pyoArgsAssert(self, "SB", title, wxnoserver)
        createSpectrumWindow(self, title, wxnoserver)

    def _setViewFrame(self, frame):
        self.viewFrame = frame

    def refreshView(self):
        """
        Updates the graphical display of the spectrum.

        Called automatically by the internal timer.

        """
        self.points = [obj.display() for obj in self._base_objs]
        if self._function != None:
            self._function(self.points)
        if self.viewFrame != None:
            self.viewFrame.update(self.points)

    @property
    def input(self):
        """PyoObject. Input signal to process."""
        return self._input
    @input.setter
    def input(self, x): self.setInput(x)

    @property
    def size(self):
        """int. FFT size."""
        return self._size
    @size.setter
    def size(self, x): self.setSize(x)

    @property
    def wintype(self):
        """int. Windowing method."""
        return self._wintype
    @wintype.setter
    def wintype(self, x): self.setWinType(x)

    @property
    def gain(self):
        """float. Sets the gain of the analysis data."""
        return self._gain
    @gain.setter
    def gain(self, x): self.setGain(x)

    @property
    def lowbound(self):
        """float. Lowest frequency (multiplier of sr) to output."""
        return self._lowbound
    @lowbound.setter
    def lowbound(self, x): self.setLowbound(x)

    @property
    def highbound(self):
        """float. Highest frequency (multiplier of sr) to output."""
        return self._highbound
    @highbound.setter
    def highbound(self, x): self.setHighbound(x)

    @property
    def width(self):
        """int. Width, in pixels, of the current display."""
        return self._width
    @width.setter
    def width(self, x): self.setWidth(x)

    @property
    def height(self):
        """int. Height, in pixels, of the current display."""
        return self._height
    @height.setter
    def height(self, x): self.setHeight(x)

    @property
    def fscaling(self):
        """boolean. Scaling of the frequency display."""
        return self._fscaling
    @fscaling.setter
    def fscaling(self, x): self.setFscaling(x)

    @property
    def mscaling(self):
        """boolean. Scaling of the magnitude display."""
        return self._mscaling
    @mscaling.setter
    def mscaling(self, x): self.setMscaling(x)
Esempio n. 38
0
class Scope(PyoObject):
    """
    Oscilloscope - audio waveform display.

    Oscilloscopes are used to observe the change of an electrical
    signal over time.

    :Parent: :py:class:`PyoObject`

    :Args:

        input : PyoObject
            Input signal to process.
        length : float, optional
            Length, in seconds, of the displayed window. Can't be a list.
            Defaults to 0.05.
        gain : float, optional
            Linear gain applied to the signal to be displayed.
            Can't be a list. Defaults to 0.67.
        function : python callable, optional
            If set, this function will be called with samples (as
            list of lists, one list per channel). Useful if someone
            wants to save the analysis data into a text file.
            Defaults to None.

    .. note::

        Scope has no `out` method.

        Scope has no `mul` and `add` attributes.

    >>> s = Server().boot()
    >>> s.start()
    >>> a = Sine([100,100.2], mul=0.7)
    >>> b = Noise(0.1)
    >>> scope = Scope(a+b)

    """
    def __init__(self, input, length=0.05, gain=0.67, function=None):
        pyoArgsAssert(self, "oNNC", input, length, gain, function)
        PyoObject.__init__(self)
        self.points = None
        self.viewFrame = None
        self._input = input
        self._length = length
        self._gain = gain
        self._function = function
        self._width = 500
        self._height = 400
        self._in_fader = InputFader(input)
        in_fader, lmax = convertArgsToLists(self._in_fader)
        self._base_objs = [Scope_base(wrap(in_fader,i), length) for i in range(lmax)]
        self._timer = Pattern(self.refreshView, length).play()
        if function == None:
            self.view()

    def setInput(self, x, fadetime=0.05):
        """
        Replace the `input` attribute.

        :Args:

            x : PyoObject
                New signal to process.
            fadetime : float, optional
                Crossfade time between old and new input. Default to 0.05.

        """
        pyoArgsAssert(self, "oN", x, fadetime)
        self._input = x
        self._in_fader.setInput(x, fadetime)

    def setLength(self, x):
        """
        Replace the `length` attribute.

        :Args:

            x : float
                new `length` attribute.

        """
        pyoArgsAssert(self, "N", x)
        self._length = x
        self._timer.time = x
        [obj.setLength(x) for obj in self._base_objs]

    def setGain(self, x):
        """
        Set the gain boost applied to the analysed data. For drawing purpose.

        :Args:

            x : float
                new `gain` attribute, as linear values.

        """
        pyoArgsAssert(self, "n", x)
        self._gain = x
        x, lmax = convertArgsToLists(x)
        [obj.setGain(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def poll(self, active):
        """
        Turns on and off the analysis polling.

        :Args:

            active : boolean
                If True, starts the analysis polling, False to stop it.
                defaults to True.

        """
        pyoArgsAssert(self, "B", active)
        if active:
            self._timer.play()
        else:
            self._timer.stop()

    def setWidth(self, x):
        """
        Gives the width of the display to the analyzer.

        The analyzer needs this value to construct the list
        of points to draw on the display.

        :Args:

            x : int
                Width of the display in pixel value. The default
                width is 500.

        """
        pyoArgsAssert(self, "I", x)
        self._width = x
        [obj.setWidth(x) for obj in self._base_objs]

    def setHeight(self, x):
        """
        Gives the height of the display to the analyzer.

        The analyzer needs this value to construct the list
        of points to draw on the display.

        :Args:

            x : int
                Height of the display in pixel value. The default
                height is 400.

        """
        pyoArgsAssert(self, "I", x)
        self._height = x
        [obj.setHeight(x) for obj in self._base_objs]

    def view(self, title="Scope", wxnoserver=False):
        """
        Opens a window showing the result of the analysis.

        :Args:

            title : string, optional
                Window title. Defaults to "Spectrum".
            wxnoserver : boolean, optional
                With wxPython graphical toolkit, if True, tells the
                interpreter that there will be no server window.

        If `wxnoserver` is set to True, the interpreter will not wait for
        the server GUI before showing the controller window.

        """
        pyoArgsAssert(self, "SB", title, wxnoserver)
        createScopeWindow(self, title, wxnoserver)

    def setFunction(self, function):
        """
        Sets the function to be called to retrieve the analysis data.

        :Args:

            function : python callable
                The function called by the internal timer to retrieve the
                analysis data. The function must be created with one argument
                and will receive the data as a list of lists (one list per channel).

        """
        pyoArgsAssert(self, "C", function)
        self._function = getWeakMethodRef(function)

    def _setViewFrame(self, frame):
        self.viewFrame = frame

    def refreshView(self):
        """
        Updates the graphical display of the scope.

        Called automatically by the internal timer.

        """
        self.points = [obj.display() for obj in self._base_objs]
        if self.viewFrame != None:
            self.viewFrame.update(self.points)
        if self._function is not None:
            self._function(self.points)

    @property
    def input(self):
        """PyoObject. Input signal to process."""
        return self._input
    @input.setter
    def input(self, x): self.setInput(x)

    @property
    def length(self):
        """float. Window length."""
        return self._length
    @length.setter
    def length(self, x): self.setLength(x)

    @property
    def gain(self):
        """float. Sets the gain of the analysis data."""
        return self._gain
    @gain.setter
    def gain(self, x): self.setGain(x)
Esempio n. 39
0
                to = ["*****@*****.**",
                      "*****@*****.**",
                      "*****@*****.**"]
                title = u"test title here"
                content = """
Begin of test<br/>
<embed type="application/x-shockwave-flash" src="http://www.odeo.com/flash/audio_player_standard_gray.swf" width="400" height="52" allowScriptAccess="always" wmode="transparent" flashvars="external_url=http://172.29.7.127:8000/static/media/35130a760bfc7e5054526ce94c17004f.mp3" />
Another
 <embed src="http://172.29.7.127:8000/static/media/35130a760bfc7e5054526ce94c17004f.mp3" loop=false autostart=false name="IMG_English" width="300" height="20" /><br/>End of test
"""
                mail.sendMail(to, title, content.decode("utf-8"))
    else:
        # send web pages to mail Subscriber
        logger.info("Begin to send email ...")

        pat = Pattern()
        db = CrawlDB()
        pages = db.getPages()
        if pages:
            logger.debug("Fetched %s pages." % (len(pages)))
            for page in pages:
                addrlist = db.getEmailByPid(page["pid"])
                if addrlist:
                    logger.debug("send mail to %s persons..." % (len(addrlist)))
                    content = pat.sub(page["content"])

                    if mail.sendMail(addrlist,
                                     page["title"],
                                     content):
                        db.setUrl(page["url"])
                        logger.info("Page [%s] is sent to %s\n\n%s\n\n" %
Esempio n. 40
0
class LocalWeb(object):
    """Constants that represent URLs and images for local content. """

    _ip_host = '127.0.0.1'
    _domain_host = 'localhost.allizom.org'
    _port = parse_args().port
    """Simple blank HTML page."""
    BLANK_PAGE = 'http://%s:%s/blank.htm' % (_ip_host, _port)
    BLANK_PAGE_2 = 'http://%s:%s/blank.htm' % (_domain_host, _port)
    """Local Firefox site."""
    FIREFOX_TEST_SITE = 'http://%s:%s/firefox/' % (_ip_host, _port)
    FIREFOX_TEST_SITE_2 = 'http://%s:%s/firefox/' % (_domain_host, _port)
    FIREFOX_LOGO = Pattern('firefox_logo.png')
    FIREFOX_IMAGE = Pattern('firefox_full.png')
    FIREFOX_BOOKMARK = Pattern('firefox_bookmark.png')
    FIREFOX_BOOKMARK_SMALL = Pattern('firefox_bookmark_small.png')
    """Local Firefox Focus site."""
    FOCUS_TEST_SITE = 'http://%s:%s/focus/' % (_ip_host, _port)
    FOCUS_TEST_SITE_2 = 'http://%s:%s/focus/' % (_domain_host, _port)
    FOCUS_LOGO = Pattern('focus_logo.png')
    FOCUS_IMAGE = Pattern('focus_full.png')
    FOCUS_BOOKMARK = Pattern('focus_bookmark.png')
    FOCUS_BOOKMARK_SMALL = Pattern('focus_bookmark_small.png')
    """Local Mozilla site."""
    MOZILLA_TEST_SITE = 'http://%s:%s/mozilla/' % (_ip_host, _port)
    MOZILLA_TEST_SITE_2 = 'http://%s:%s/mozilla/' % (_domain_host, _port)
    MOZILLA_LOGO = Pattern('mozilla_logo.png')
    MOZILLA_IMAGE = Pattern('mozilla_full.png')
    MOZILLA_BOOKMARK = Pattern('mozilla_bookmark.png')
    MOZILLA_BOOKMARK_SMALL = Pattern('mozilla_bookmark_small.png')
    """Local Pocket site."""
    POCKET_TEST_SITE = 'http://%s:%s/pocket/' % (_ip_host, _port)
    POCKET_TEST_SITE_2 = 'http://%s:%s/pocket/' % (_domain_host, _port)
    POCKET_LOGO = Pattern('pocket_logo.png')
    POCKET_IMAGE = Pattern('pocket_full.png')
    POCKET_BOOKMARK = Pattern('pocket_bookmark.png')
    POCKET_BOOKMARK_SMALL = Pattern('pocket_bookmark_small.png')
    """Soap Wiki Test Site"""
    SOAP_WIKI_TEST_SITE = 'http://%s:%s/soap_wiki_test_site/' % (_ip_host,
                                                                 _port)
    SOAP_WIKI_1_OF_2_MATCHES = Pattern('1_of_2_matches.png')
    SOAP_WIKI_2_OF_2_MATCHES = Pattern('2_of_2_matches.png')
    SOAP_WIKI_CLEANING_SEE_SELECTED_LABEL = Pattern(
        'cleaning_see_selected_label.png')
    SOAP_WIKI_OPERATING_ALL = Pattern('operating_all.png')
    SOAP_WIKI_OPERATING_ALL_HIGHLIGHTED = Pattern(
        'operating_all_highlighted.png')
    SOAP_WIKI_OPERATING_DISPARATE = Pattern('operating_disparate.png')
    SOAP_WIKI_OPERATING_DISPARATE_HIGHLIGHTED = Pattern(
        'operating_disparate_highlighted.png')
    SOAP_WIKI_SEE_LABEL = Pattern('see_label.png')
    SOAP_WIKI_SEE_LABEL_UNHIGHLITED = Pattern('see_label_unhighlited.png')
    SOAP_WIKI_SOAP_ENVELOPE_LABEL_SELECTED = Pattern(
        'soap_envelope_label_selected.png')
    SOAP_WIKI_SOAP_LABEL = Pattern('soap_label.png')
    SOAP_WIKI_SOAP_LINK_HIGHLIGHTED = Pattern('soap_link_highlighted.png')
    SOAP_WIKI_SOAP_XML_LABEL = Pattern('soap_xml_label.png')
    SOAP_WIKI_TEST_LABEL_PATTERN = Pattern('test_label_pattern.png')
    """Local files samples."""
    SAMPLE_FILES = 'http://%s:%s/files/' % (_ip_host, _port)
    """about:preferences#privacy"""
    ABOUT_PREFERENCES_PRIVACY_ADDRESS = Pattern(
        'about_preferences_privacy_address.png')
    """CNN Site"""
    CNN_LOGO = Pattern('cnn_logo.png')
    CNN_BLOCKED_CONTENT_ADV = Pattern('cnn_blocked_content.png')
 def make_waffle_pattern(self):
     waffle=Pattern('Waffle')
     waffle.add_row(['p2','*RT','p2','rep from *'])
     waffle.add_row(['k2','*p2','k2','rep from *'])
     waffle.add_row(['p1','*k2tog','[yo]twice','ssk','rep from * to last st','p1'])
     waffle.add_row(['p2','*k1p1 in double yo','p2','rep from *'])
     waffle.add_row(['k2','*p2','LT','rep from * to last 4 sts','p2','k2'])
     waffle.add_row(['p2','*k2','p2','rep from *'])
     waffle.add_row(['p1','yo','*ssk','k2tog','[yo]twice','rep from * to last 5 sts','ssk','k2tog','yo','p1'])
     waffle.add_row(['k1','*p2','k1p1 into double yo','rep from * to last 4sts','p2','k2'])
     return waffle
 def make_double_leaf_pattern(self):
     dlp = Pattern('DoubleLeafPattern')
     dlp.add_row(['p8','p2tog','k1','yo','k1','yo','k1','k1fb','k1''k1fb','k1','yo','k1','yo','k1','p2tog','p8'])
     dlp.add_row(['k9','p5','k1','p3','k1','p5','p9'])
     dlp.add_row(['p7','p2tog','k2','yo','k1','yo','k2','p1fb','k3','p1fb','k2','yo','k1','yo','k2','p2tog','p7')]
     dlp.add_row(['k8','p7','k2','p3','k2','p7','k8'])
     dlp.add_row(['p6','p2tog','k3','yo','k1','yo','k3','p1fb','p1','k3','p1','p1fb','k3','yo','k1','yo','k3','p2tog','p6'])
     dlp.add_row(['k7','p9','k3','p3','k3','p9','k7'])
     dlp.add_row(['p5','p2tog','k4','yo','k1','yo','k4','p1fb','p2','k3','p2','p1fb','k4','yo','k1','yo','k4','p2tog','p5'])
     dlp.add_row(['k6','p11','k4','p3','k4','p11','k6'])
     dlp.add_row(['p4','p2tog','ssk','k7','k2tog','p1fb','p3','k3','p3','p1fb','ssk','k7','k2tog','p2tog','p4'])
     dlp.add_row(['k5','p9','k5','p3','k5','p9','k5'])
     dlp.add_row(['p3','p2tog','ssk','k5','k2tog','p1fb','p4','k3','p4','p1fb','ssk','k5','k2tog','p2tog','p3'])
     dlp.add_row(['k4','p7','k6','p3','k6','p7','k4'])
     dlp.add_row(['p2','p2tog','ssk','k3','k2tog','p1fb','p5','k2','m1','k1','m1','k1','p5','p1fb','ssk','k2','k2tog','p2tog','p2'])
     dlp.add_row(['k3','p5','k7','p5','k7','p5','k3'])
     dlp.add_row(['p1','p2tog','ssk','k2','k2tog','p1fb','p6','k1','m1','k3','m1','k1','p6','p1fb','ssk','k2','k2tog','p2tog','p1'])
     dlp.add_row(['k2','p3','k8','p7','k7','p3','k2'])
     dlp.add_row(['p2','sl2','k1','p2 sso','p6','p2tog','k1','m1','k5','m1','k1','p2tog','p6','sl2','k1','p2 sso','p2'])
     dlp.add_row(['k10','p9','k10'])
     return dlp
import cv2
import numpy as np
import sys
import os
from matplotlib import pyplot as plt
import bloodstain
import json
import csv
from parse_arguements import parse_args
from pattern import Pattern
import progressbar

path = '/media/cba62/Elements/Cropped Data/'
save_path = '/media/cba62/Elements/Result_data/'
pattern = Pattern()


def CLI(args={}):
    args = parse_args() if not args else args
    filename = None if not args['filename'] else path + args['filename']
    full_path = args['full_path']
    if full_path:
        filename = full_path

    if not filename:
        print("No file selected")
        return
    print("\nProcessing: " + filename)

    save_path = set_save_path(filename, args['output_path'])
    pattern.scale = args['scale']
Esempio n. 44
0
 def random(self, difficulty):
     board = self.get_board()
     p = Pattern.random_difficulty()
     print(p)
     return p.set_board(board)
Esempio n. 45
0
            m2_int_sel,
            m2_int_sel_in,
            m2_int_sel_out,
            m2_int_sel_gpot,
            m2_int_sel_spike,
            np.zeros(N2_gpot, dtype=np.double),
            np.zeros(N2_spike, dtype=int), ['interface', 'io', 'type'],
            CTRL_TAG,
            GPOT_TAG,
            SPIKE_TAG,
            device=1,
            time_sync=True)

    # Make sure that all ports in the patterns' interfaces are set so
    # that they match those of the modules:
    pat12 = Pattern(m1_int_sel, m2_int_sel)
    pat12.interface[m1_int_sel_out_gpot] = [0, 'in', 'gpot']
    pat12.interface[m1_int_sel_in_gpot] = [0, 'out', 'gpot']
    pat12.interface[m1_int_sel_out_spike] = [0, 'in', 'spike']
    pat12.interface[m1_int_sel_in_spike] = [0, 'out', 'spike']
    pat12.interface[m2_int_sel_in_gpot] = [1, 'out', 'gpot']
    pat12.interface[m2_int_sel_out_gpot] = [1, 'in', 'gpot']
    pat12.interface[m2_int_sel_in_spike] = [1, 'out', 'spike']
    pat12.interface[m2_int_sel_out_spike] = [1, 'in', 'spike']
    pat12['/a/out/gpot0', '/b/in/gpot0'] = 1
    pat12['/a/out/gpot1', '/b/in/gpot1'] = 1
    pat12['/b/out/gpot0', '/a/in/gpot0'] = 1
    pat12['/b/out/gpot1', '/a/in/gpot1'] = 1
    pat12['/a/out/spike0', '/b/in/spike0'] = 1
    pat12['/a/out/spike1', '/b/in/spike1'] = 1
    pat12['/b/out/spike0', '/a/in/spike0'] = 1
 def get_annotation_param(pattern: Pattern):
     annotation_param = pattern.get_annotation_parameter('blue')
     annotation_param.xy = PlotterInterface.get_xy_from_timestamp_to_date_number(annotation_param.xy)
     annotation_param.xy_text = PlotterInterface.get_xy_from_timestamp_to_date_number(annotation_param.xy_text)
     return annotation_param
Esempio n. 47
0
 def get_value(self):
     if self.is_stable():
         pattern = Pattern.from_index(self.allowed_patterns[0])
         return pattern.get()
     return -1
Esempio n. 48
0
from pattern import Pattern

#----test some known valid cases

p = Pattern([4,4,1])
if(p.is_valid() == False):
	print "test_fail, pattern [4,4,1] should be a valid siteswap"
if(p.particles != 3):
	print "test_fail, pattern [4,4,1] should have 3 balls"

p = Pattern([1,-1,0])
if(p.is_valid() == False):
	print "test_fail, pattern [1,-1,0] should be a valid siteswap"
if(p.particles != 0):
	print "test_fail, pattern [1,-1,0] should have 0 balls"
	
p = Pattern([2,3,3,-2,2,-2,1,1])
if(p.is_valid() == False):
	print "test_fail, pattern [2,3,3,-2,2,-2,1,1] should be a valid siteswap"
if(p.particles != 1):
	print "test_fail, pattern [2,3,3,-2,2,-2,1,1] should have 1 ball"

#----test some known invalid cases
#we try to construct the objects, and in case it fails and throws an error
# then we know everything went as expeced
construct_fail = False
try:
	p = Pattern([2,1,0])
except ValueError as e:
	construct_fail = True
Esempio n. 49
0
			num_users = 0
			if len(value["user"]) > 0:
				num_users = len(value["user"])
				selected_users = value["user"]
			else:
				num_users = float(self.attributes["user"]["domain"])*float(value["groupSupport"])
				while len(selected_users) < num_users:
					selected = random.randrange(1, int(self.attributes["user"]["domain"]))
					selected_user = self.attributes["user"]["represent"] + str(selected)
					if selected_user not in selected_users:
						selected_users.append(selected_user)
			
			for user in selected_users:
				if user not in self.exp_sequences:
					self.exp_sequences[user] = {}
				self.exp_sequences[user][key] = expanded

if __name__ == '__main__':
	attribute = Attribute()
	attribute.load_dist_json()
	attribute.load_attr_cvs()
	
	pattern = Pattern(attribute.sem_to_rep)
	pattern.load()
	
	expanded_seq = Sequencepat(attribute.distribution, pattern.patterns)
	expanded_seq.expand()
	#print expanded_seq.exp_sequences
	print json.dumps(expanded_seq.exp_sequences)

Esempio n. 50
0
    def emulate(n, steps):
        assert(n>1)
        n = str(n)

        # Set up emulation:
        man = Manager(get_random_port(), get_random_port(), get_random_port())
        man.add_brok()

        m1_int_sel_in_gpot = '/a/in/gpot0,/a/in/gpot1'
        m1_int_sel_out_gpot = '/a/out/gpot0,/a/out/gpot1'
        m1_int_sel_in_spike = '/a/in/spike0,/a/in/spike1'
        m1_int_sel_out_spike = '/a/out/spike0,/a/out/spike1'
        m1_int_sel = ','.join([m1_int_sel_in_gpot, m1_int_sel_out_gpot,
                               m1_int_sel_in_spike, m1_int_sel_out_spike])
        m1_int_sel_in = ','.join([m1_int_sel_in_gpot, m1_int_sel_in_spike])
        m1_int_sel_out = ','.join([m1_int_sel_out_gpot, m1_int_sel_out_spike])
        m1_int_sel_gpot = ','.join([m1_int_sel_in_gpot, m1_int_sel_out_gpot])
        m1_int_sel_spike = ','.join([m1_int_sel_in_spike, m1_int_sel_out_spike])
        N1_gpot = SelectorMethods.count_ports(m1_int_sel_gpot)
        N1_spike = SelectorMethods.count_ports(m1_int_sel_spike)
        m1 = MyModule(m1_int_sel,
                      m1_int_sel_in, m1_int_sel_out,
                      m1_int_sel_gpot, m1_int_sel_spike,
                      np.zeros(N1_gpot, np.float64),
                      np.zeros(N1_spike, int), ['interface', 'io', 'type'],
                      man.port_data, man.port_ctrl, man.port_time, 'm1', None,
                      False, True)
        man.add_mod(m1)

        m2_int_sel_in_gpot = '/b/in/gpot0,/b/in/gpot1'
        m2_int_sel_out_gpot = '/b/out/gpot0,/b/out/gpot1'
        m2_int_sel_in_spike = '/b/in/spike0,/b/in/spike1'
        m2_int_sel_out_spike = '/b/out/spike0,/b/out/spike1'
        m2_int_sel = ','.join([m2_int_sel_in_gpot, m2_int_sel_out_gpot,
                               m2_int_sel_in_spike, m2_int_sel_out_spike])
        m2_int_sel_in = ','.join([m2_int_sel_in_gpot, m2_int_sel_in_spike])
        m2_int_sel_out = ','.join([m2_int_sel_out_gpot, m2_int_sel_out_spike])
        m2_int_sel_gpot = ','.join([m2_int_sel_in_gpot, m2_int_sel_out_gpot])
        m2_int_sel_spike = ','.join([m2_int_sel_in_spike, m2_int_sel_out_spike])
        N2_gpot = SelectorMethods.count_ports(m2_int_sel_gpot)
        N2_spike = SelectorMethods.count_ports(m2_int_sel_spike),
        m2 = MyModule(m2_int_sel,
                      m2_int_sel_in, m2_int_sel_out,
                      m2_int_sel_gpot, m2_int_sel_spike,
                      np.zeros(N2_gpot, np.float64),
                      np.zeros(N2_spike, int), ['interface', 'io', 'type'],
                      man.port_data, man.port_ctrl, man.port_time, 'm2', None,
                      False, True)
        man.add_mod(m2)

        # Make sure that all ports in the patterns' interfaces are set so 
        # that they match those of the modules:
        pat12 = Pattern(m1_int_sel, m2_int_sel)
        pat12.interface[m1_int_sel_out_gpot] = [0, 'in', 'gpot']
        pat12.interface[m1_int_sel_in_gpot] = [0, 'out', 'gpot']
        pat12.interface[m1_int_sel_out_spike] = [0, 'in', 'spike']
        pat12.interface[m1_int_sel_in_spike] = [0, 'out', 'spike']
        pat12.interface[m2_int_sel_in_gpot] = [1, 'out', 'gpot']
        pat12.interface[m2_int_sel_out_gpot] = [1, 'in', 'gpot']
        pat12.interface[m2_int_sel_in_spike] = [1, 'out', 'spike']
        pat12.interface[m2_int_sel_out_spike] = [1, 'in', 'spike']
        pat12['/a/out/gpot0', '/b/in/gpot0'] = 1
        pat12['/a/out/gpot1', '/b/in/gpot1'] = 1
        pat12['/b/out/gpot0', '/a/in/gpot0'] = 1
        pat12['/b/out/gpot1', '/a/in/gpot1'] = 1
        pat12['/a/out/spike0', '/b/in/spike0'] = 1
        pat12['/a/out/spike1', '/b/in/spike1'] = 1
        pat12['/b/out/spike0', '/a/in/spike0'] = 1
        pat12['/b/out/spike1', '/a/in/spike1'] = 1
        man.connect(m1, m2, pat12, 0, 1)

        # To set the emulation to exit after executing a fixed number of steps,
        # start it as follows and remove the sleep statement:
        man.start(steps=steps)
        # man.start()
        # time.sleep(2)
        man.stop()
        return m1
Esempio n. 51
0
def union2patterns(sp,op):

	# first sp then op
	# input two graph patterns and generate a list of new patterns

	dLimit = min(sp.diameter(),op.diameter());
	# print "dlimit = ", dLimit;

	newPatternList = list();
	# last node
	L = "ln";
	# diameter
	D = "di";
	# mappings
	M = "m"

	mapList = list();
	tMapList = list();

	# init
	d = dict();
	d[D] = 0;
	d[M] = dict();

	d[M][sp.x] = op.x;
	d[L] = sp.x;

	tMapList.append(d);

	# pop out from templist and find new mappings, start from last node
	while len(tMapList)!=0:
		# first add it to final maplist;
		cmap = tMapList.pop();
		# print cmap;
		mapList.append(cmap);

		if cmap[D]>= dLimit:
			print "terminate due to the diameter limit."
			continue;

		for snb in sp.g.neighbors(cmap[L]):
			snb_label = sp.g.node[snb]["l"];
			# print "snbLabel in snb", snb_label;

			# print op.g.nodes(data=True);
			for onb in op.g.neighbors(cmap[M][cmap[L]]):
				onb_label = op.g.node[onb]["l"]
				if onb_label == snb_label:
					# print snb ,"->", onb;
					# print "potential cmap[M]:",cmap[M];
					# find a new map;
					if snb not in cmap and onb not in cmap[M].values():
						# print "confirmed as new.";
						mapd = dict();
						mapd[M] = cmap[M].copy();
						# depth +=1
						mapd[D]=cmap[D]+1;
						mapd[M][snb] = onb;
						mapd[L] = snb;
						# print mapd;
						tMapList.append(mapd);
	
	# print "merged result:",len(mapList)
	for mapping in mapList:
		# print "last=",mapping[L],"d=",mapping[D],mapping[M];
		# print "mappingD = ",mapping[M]

		# generate new patterns
		np = Pattern();
		np.x = sp.x;
		np.y = sp.y;
		np.g = nx.union(sp.g,op.g,"SO");
		# print "after norename new graph nodes = ", np.g.nodes(data=True)
		# print "after norename new graph edges = ", np.g.edges()

		# print "mapping" ,mapping[M];
		# mapping

		for k in mapping[M]:
			# virtual node, to be merged and removed.
			vnode = "O"+mapping[M][k];
			target = "S"+k;
			# print "vnode=",vnode,"target=",target;
			for eo in np.g.out_edges(vnode):
				if np.g.has_edge(target, eo[1]) == False:
					np.g.add_edge(target,eo[1]);
				np.g.remove_edge(eo[0],eo[1]);
			for ei in np.g.in_edges(vnode):
				if np.g.has_edge(ei[0], target) == False:
					np.g.add_edge(ei[0],target);
				np.g.remove_edge(ei[0],ei[1]);
			np.g.remove_node(vnode);

		# print "after norename new graph edges -2 = ", np.g.edges()
		
		# rename
		rename = dict();
		index = 1;
		for node in np.g.nodes():
			rename[node] = str(index);
			index = index +1;
		np.x = rename["S"+np.x];
		np.y = rename["S"+np.y];
		np.g = nx.relabel_nodes(np.g,rename, copy=False)

		# add merged originals
		np.covered = sp.covered.union(op.covered);

		# WARN:np is always be supergraph of sp and op,
		# but networkx will not allways get subgraph_isomorphism
		# since networkx only support node-induced graph isomorphism

		# GM1 = isomorphism.DiGraphMatcher(np.g,sp.g,node_match);
		# print "subgraph_isomorphism with source graph=",GM1.subgraph_is_isomorphic();
		# GM2 = isomorphism.DiGraphMatcher(np.g,op.g,node_match);
		# print "subgraph_isomorphism with others graph=",GM2.subgraph_is_isomorphic();

		# if(GM1.subgraph_is_isomorphic()==False):
		# 	print "s nodes = ", sp.g.nodes(data=True)
		# 	print "s graph = ",sp.g.edges();
		# 	print "====================="
		# 	print "new graph nodes = ", np.g.nodes(data=True)
		# 	print "new graph = ",np.g.edges();

		# if(GM2.subgraph_is_isomorphic()==False):
		# 	print "o nodes = ", op.g.nodes(data=True)
		# 	print "o graph = ",op.g.edges();
		# 	print "x=",op.x, "y=",op.y;
		# 	print "====================="
		# 	print "new graph nodes = ", np.g.nodes(data=True)
		# 	print "new graph = ",np.g.edges();
		# 	print "x=",np.x, "y=",np.y;

		newPatternList.append(np);

	return newPatternList;
Esempio n. 52
0
 def test_load_bitmap(self):
     p = Pattern()
     self.assertRaises(FileNotFoundError, p.load_bitmap, 'blah')
Esempio n. 53
0
    m2 = MyModule(m2_int_sel, m2_int_sel_in, m2_int_sel_out,
                  np.zeros(5, dtype=np.float),
                  ['interface', 'io', 'type'],
                  man.port_data, man.port_ctrl, man.port_time, 'm2   ', False,
                  True)
    man.add_mod(m2)
    m3 = MyModule(m3_int_sel, m3_int_sel_in, m3_int_sel_out,
                  np.zeros(4, dtype=np.float),
                  ['interface', 'io', 'type'], 
                  man.port_data, man.port_ctrl, man.port_time, 'm3   ', False,
                  True)
    man.add_mod(m3)

    # Make sure that all ports in the patterns' interfaces are set so 
    # that they match those of the modules:
    pat12 = Pattern(m1_int_sel, m2_int_sel)
    pat12.interface[m1_int_sel_out] = [0, 'in']
    pat12.interface[m1_int_sel_in] = [0, 'out']
    pat12.interface[m2_int_sel_in] = [1, 'out']
    pat12.interface[m2_int_sel_out] = [1, 'in']
    pat12['/a[2]', '/b[0]'] = 1
    pat12['/a[3]', '/b[1]'] = 1
    pat12['/b[3]', '/a[0]'] = 1
    man.connect(m1, m2, pat12, 0, 1)

    pat23 = Pattern(m2_int_sel, m3_int_sel)
    pat23.interface[m2_int_sel_out] = [0, 'in']
    pat23.interface[m2_int_sel_in] = [0, 'out']
    pat23.interface[m3_int_sel_in] = [1, 'out']
    pat23.interface[m3_int_sel_out] = [1, 'in']
    pat23['/b[4]', '/c[0]'] = 1
Esempio n. 54
0
def exit(pattern):
    sys.exit()


action_map = {
    'r': read_pattern_from_file,
    'a': add_note_to_pattern,
    'w': write_pattern_to_file,
    'l': change_pattern_length,
    'd': delete_note_from_pattern,
    'dn': delete_note_occurrences_from_pattern,
    'da': delete_all_notes_from_pattern,
    'p': play_pattern,
    'x': exit,
}

if __name__ == "__main__":
    setup_folders()
    menu_choice = input(
        'enter length of pattern or enter \'r\' to load pattern >')
    if menu_choice == 'r':
        bank, pad = get_user_input(['bank', 'pad'])
        pattern = read_pattern(bank, pad)
    else:
        pattern = Pattern(int(menu_choice))
    while menu_choice != 'x':
        print(pattern)
        menu_choice = menu()
        pattern = action_map[menu_choice](pattern)
Esempio n. 55
0
	minDistance = 1000
	word_u = unicode(word)
	for wazn in templates:
		wazn_u = unicode(wazn)
		distanceI = distance(word_u, wazn_u)
		if distanceI < minDistance:
			minDistance = distanceI
			template = wazn
			continue
		if distanceI == minDistance:
			template = template + '+' + wazn
	if not '+' in template:
		template = template + ";"
	return template

def getTemplate(word):
	template = getTemplateNoDiac(word)
	if not '+' in template:
		return template
	return getTemplateFromList(word, template)

if __name__ == '__main__':
        from pattern import Pattern
        import sys
        from sys import argv
        script, word = argv
        word = unicode(word, 'utf-8')
        wordpat = Pattern(word)
        print wordpat.getPatternCode()
        print wordpat.getUnvocalized()
Esempio n. 56
0
                    new_seq_item.append(item)
                expanded.append(new_seq_item)
            if (len(value["sequence"]) == 0):
                new_seq_item = []
                for item in value["itemset"]:
                    new_seq_item.append(item)
                expanded.append(new_seq_item)
            num_users = float(self.attributes["user"]["domain"]) * float(
                value["support"])
            for i in range(int(num_users)):
                selected = random.randrange(
                    1, int(self.attributes["user"]["domain"]))
                selected_user = self.attributes["user"]["represent"] + str(
                    selected)
                if selected_user not in self.exp_sequences:
                    self.exp_sequences[selected_user] = {}
                self.exp_sequences[selected_user][key] = expanded


if __name__ == '__main__':
    attribute = Attribute()
    attribute.load_dist_json()
    attribute.load_attr_cvs()

    pattern = Pattern(attribute.sem_to_rep)
    pattern.load()

    expanded_seq = Sequencepat(attribute.distribution, pattern.patterns)
    expanded_seq.expand()
    print expanded_seq.exp_sequences
Esempio n. 57
0
	while len(bigQ)!=0:
		p = bigQ.pop()
		print "p.id=",p.id,"p.x,p.y",p.x, p.y
		if len(shouldHaveAll.difference(p.covered))!=0:
			# not contain all required nodes
			print "discards p id=",p.id,"since don't covered all should cover."
			pass;

		else:
			#generate several Q'

			# test if the new pattern is duplicates.

			for ynode in p.y:
				# edges every x->y
				r = Pattern();
				r.g = p.g.copy();
				r.x = p.x;
				r.y = p.y.copy();
				r.y.remove(ynode);
				print r.x,"---",r.y
				print "edgesize,b4 edgessize =",len(r.g.edges()),"degree of y =",ynode,r.g.degree(ynode)
				r.g.remove_edge(p.x,ynode);
				print "edgesize,aft edgesize =",len(r.g.edges()),"degree of y =",ynode,r.g.degree(ynode)
				if r.g.degree(ynode)==0:
					print "remove y", ynode
					r.g.remove_node(ynode); 
					
				# print float(suppThreshold)/confThreshold;
				if computeSupport(baseG,r) <= float(suppThreshold)/confThreshold:
					# WARN: r will be 0;