Ejemplo n.º 1
0
    def make(self, ontname, threshold, link):
        weighted_tokens = WeightAttacher.make(self.user_stories, self.weights)

        self.onto = Ontology(ontname, self.user_stories)
        self.prolog = Ontology(ontname, self.user_stories)

        pf = PatternFactory(self.onto, self.prolog, weighted_tokens)
        self.onto = pf.make_patterns(self.user_stories, threshold)
        self.prolog = pf.prolog

        if link:
            self.link_to_story(self.onto.classes, self.user_stories)

        g = Generator(self.onto.classes, self.onto.relationships)
        g_prolog = Generator(self.prolog.classes, self.prolog.relationships,
                             False)

        per_role_out = []
        per_role_onto = self.get_per_role(self.user_stories, link)

        for p in per_role_onto:
            per_role_out.append([p[0].replace('/', '_'), p[1].prt(self.onto)])

        return g.prt(self.onto), g_prolog.prt(
            self.prolog), self.onto, self.prolog, per_role_out
Ejemplo n.º 2
0
def normal_qrcode():
    text = request.json.get('text')
    try:
        result_base64 = Generator.gen_normal_qrcode(text)
    except Exception as e:
        return jsonify({"code": 1, "message": e})
    return jsonify({"code": 0, "url": result_base64})
Ejemplo n.º 3
0
def gif_qrcode():
    picture_file = request.files['file']
    text = request.form['text']
    temp_file_name = str(
        uuid.uuid4()) + '.' + picture_file.filename.split('.')[-1:][0]
    temp_file_path = os.path.join(os.getcwd(), temp_file_name)
    picture_file.save(temp_file_path)

    try:
        result_base64 = Generator.gen_gif_qrcode(text, temp_file_path)
    except Exception as e:
        return jsonify({"code": 1, "message": e})

    return jsonify({"code": 0, "url": result_base64})
    def __iter__(self):
        base_seed = self.rng.randint(0, 2 << 32 - 1)
        worker_info = data.get_worker_info()
        if worker_info is None:
            worker_id = 0
        else:
            worker_id = worker_info.id

        seed = base_seed + worker_id

        generator = Generator(np.random.RandomState(seed))
        while True:
            example = generator.create()
            yield Environment(inputs={"text_query": example.text},
                              supervisions={"ground_truth": example.code})
Ejemplo n.º 5
0
    def get_generator(self, role, spr, link):
        role_classes = []
        role_relationships = []
        cl_names = []

        # Get classes
        for cl in self.onto.classes:
            for story in cl.stories:
                if story >= 0 and story in spr and cl.name not in cl_names:
                    role_classes.append(cl)
                    cl_names.append(cl.name)
                    if cl.parent != '':
                        for cp in self.onto.classes:
                            if cp.name == cl.parent:
                                role_classes.append(cp)

            # Get the general classes
            if cl.stories[0] == -1:
                if cl.name == 'FunctionalRole' or cl.name == 'Person':
                    role_classes.append(cl)

        story_classes = []

        # Get all relationships belonging to these classes
        for rel in self.onto.relationships:
            for story in rel.stories:
                if rel.domain in cl_names and rel.range in cl_names and story in spr:
                    role_relationships.append(rel)

            # If 'link' add these classes too
            if link:
                for story in spr:
                    if rel.domain in cl_names and rel.range == 'US' + str(
                            story):
                        role_relationships.append(rel)
                        story_classes.append(rel.range)

        # Retrieve all classes for the relationships created in link
        if link:
            for cl in self.onto.classes:
                for c in story_classes:
                    if cl.name == c:
                        role_classes.append(cl)
                if cl.name == 'UserStory':
                    role_classes.append(cl)

        return Generator(role_classes, role_relationships)
Ejemplo n.º 6
0
from flask import Flask
from config import Config
from flask_bootstrap import Bootstrap
from app.generator import Generator
app = Flask(__name__)
app.config.from_object(Config)
bootstrap = Bootstrap(app)
generator = Generator()
from app import routes

Ejemplo n.º 7
0
def test_generation():
    g = Generator(np.random.RandomState(0))
    for _ in range(10000):
        example = g.create()
        ast.parse(example.code)