示例#1
0
 def commit_to_multi_model_database(self):
     multicategory.get_selected_multi_model_database().add_object(self.result)
     model_relation = self.construct_model_relation()
     model_rel = ModelRelationship(self.name, self.source_dataset.get_model_category(), model_relation, self.result.get_model_category())
     lambda_function = self.construct_lambda_function()
     collection_rel = CollectionRelationship(self.name, self.source_dataset.get_collection(), lambda_function, self.result.get_collection())
     mor = CollectionConstructorMorphism(self.name, self.source_dataset, model_rel, collection_rel, self.result)
     multicategory.get_selected_multi_model_database().add_morphism(mor)
示例#2
0
def return_attibutes_to_build_relational_constructor(attributes_datatypes):
    target_folder_path = os.path.join(dirname, "..//..//db_files")
    model_category = TableModelCategory(
        name, list(attributes_datatypes.keys()))
    collection = TableCollection(
        name, attributes_datatypes, h5file_path=target_folder_path + "//" + name + ".h5")
    constructor = CollectionConstructor(name, model_category, collection)
    multicategory.get_selected_multi_model_database().add_object(constructor)
示例#3
0
def update_click_output(n_clicks, name):
    ctx = dash.callback_context
    if ctx.triggered:
        prop_id = ctx.triggered[0]["prop_id"].split(".")[0]
        if prop_id == "submit-final-model-category" and len(model_categories) > 0 and name != "":
            new_object = construct_converged_collection_constructor_functor(name, model_categories, added_connections)
            multicategory.get_selected_multi_model_database().add_object(new_object)
            return [html.P("New collection constructor created with the given model category. The constructor is part of the multi-model database. You can insert data into the collection in the insert tab.")]
    else:
        raise PreventUpdate
示例#4
0
def execute_multi_model_join(join_parameters):
    database = multicategory.get_selected_multi_model_database()
    domain = database.get_objects()[join_parameters["domain"]]
    target = database.get_objects()[join_parameters["target"]]
    morphism = database.get_morphisms()[join_parameters["morphism"]]
    left = join_parameters["left"]
    right = join_parameters["right"]
    second_description = join_parameters["second_description"]
    tree_attributes = join_parameters["tree_attributes"]
    join_result = MultiModelJoin(domain,
                                 morphism,
                                 target,
                                 left=left,
                                 right=right,
                                 second_description=second_description,
                                 tree_attributes=tree_attributes)
    result = join_result.get_result()
    database.add_object(result)
    database.add_morphism(join_result.get_left_leg())
    database.add_morphism(join_result.get_right_leg())
    return html.Div(children=[
        visualize(result),
        html.Br(),
        model_category_nx_grah_to_cytoscape(join_result)
    ])
示例#5
0
def update_click_output(dataset):
    if dataset != "" and dataset != None:
        objects = multicategory.get_selected_multi_model_database(
        ).get_objects()
        return build_insert_tool(objects[dataset])
    else:
        raise PreventUpdate
示例#6
0
def build_banner():
    return html.Div(
        id="banner",
        className="banner",
        children=[
            html.Div(
                id="banner-text",
                children=[
                    html.H5("MultiCategory v2.0"),
                    html.
                    H6("Applying category theory to multi-model database management systems, query processing and model transformations"
                       ),
                ],
            ),
            html.Div(
                id="selected-dataset-banner-parent",
                children=html.
                P("Selected database: " +
                  multicategory.get_selected_multi_model_database().get_name()
                  )),
            html.Div(
                id="banner-logo",
                children=[
                    html.Button(id="learn-more-button",
                                children="LEARN MORE",
                                n_clicks=0),
                    html.Img(id="logo", src=app.get_asset_url("favicon.png")),
                ],
            ),
        ],
    )
示例#7
0
def tree_attributes_input_toggle(value):
    if parameter_state["domain"] != None and parameter_state["target"] != None:
        domain = multicategory.get_selected_multi_model_database().get_objects(
        )[parameter_state["domain"]].get_model()
        if domain == "tree":
            return tree_attributes_input_builder()
    return []
示例#8
0
def second_description_input_toggle(value):
    objects = multicategory.get_selected_multi_model_database().get_objects()
    if parameter_state["domain"] != None and parameter_state["target"] != None:
        domain = objects[parameter_state["domain"]].get_model()
        target = objects[parameter_state["target"]].get_model()
        if domain == "relational" and (target == "graph" or target == "tree"):
            return second_description_input_builder()
    return []
示例#9
0
def name_input(n_clicks, name):
    ctx = dash.callback_context
    if ctx.triggered:
        prop_id = ctx.triggered[0]["prop_id"].split(".")[0]
        if prop_id == "submit-tree-constructor" and name.strip() != "":
            target_folder_path = os.path.join(dirname, "..//..//db_files")
            model_category = TreeModelCategory(name)
            collection = TreeCollection(name,
                                        target_file_path=target_folder_path)
            constructor = CollectionConstructor(name, model_category,
                                                collection)
            multicategory.get_selected_multi_model_database().add_object(
                constructor)
            return html.P("New tree collection with name '" + name +
                          "' has been added to the multi-model database."), ""
    else:
        raise PreventUpdate
示例#10
0
def update_return_attributes(selected_domain):
    if selected_domain != None:
        data_object = multicategory.get_selected_multi_model_database(
        ).get_objects()[selected_domain]
        domain_model = data_object.get_model()
        return render_return_attribute_input(domain_model, fold_query_state)
    else:
        raise PreventUpdate
示例#11
0
def update_return_attributes(selected_domain):
    if selected_domain != None:
        data_object = multicategory.get_selected_multi_model_database(
        ).get_objects()[selected_domain]
        domain_model = data_object.get_model()
        attributes = data_object.get_attributes_from_model_category()
        if domain_model != None and domain_model != "graph":
            options = [{
                'label': str(value),
                'value': str(value)
            } for value in attributes]
            return options
        else:
            raise PreventUpdate
    else:
        raise PreventUpdate
示例#12
0
def build_settings_tab():
    dbs = multicategory.get_multi_model_db_names_for_dropdown()
    selected_db = multicategory.get_selected_multi_model_database().get_name()
    return [
        html.Div(
            id="set-specs-intro-container",
            children=[
                html.
                H5("Select the preinstalled multi-model database. The default database is the e-commerce database."
                   ),
                dcc.Dropdown(id="select-multi-model-database",
                             options=dbs,
                             value=selected_db),
                html.Br(),
                build_external_database_textarea_connection()
            ]),
    ]
示例#13
0
 def __init__(self, name, source_dataset_name, filtering_condition, return_info, target_model):
     self.name = name
     self.source_dataset = multicategory.get_selected_multi_model_database().get_objects()[
         source_dataset_name]
     self.filtering_condition = filtering_condition
     self.return_info = return_info
     self.target_model = target_model
     self.result = None
     self.whole_result = []
     compiled_filtering_condition = compile(self.filtering_condition, 'filter.py', 'eval')
     self.filter_function = eval(compiled_filtering_condition)
     self.initialize_result()
     objects = self.source_dataset.get_iterable_collection_of_objects()
     self.query(objects)
     #print("Whole result: ", whole_result)
     self.result.append_to_collection(self.whole_result)
     self.commit_to_multi_model_database()
示例#14
0
def build_result_tab():
    global objects
    objects = multicategory.get_selected_multi_model_database().get_objects()
    if rel_db.connected():
        objects[str(rel_db)] = rel_db
    if graph_db.connected():
        objects[str(graph_db)] = graph_db
    initial_options = []
    for obj in objects:
        initial_options.append({'label': str(obj), 'value': str(obj)})

    return [
        html.Div(
            id="set-specs-intro-container",
            children=[
                html.Div(
                    id="result-tab-main-container",
                    children=[
                        html.Div(
                            id="select-visualized-object",
                            children=[
                                html.
                                H4("This area is for creating selective queries and creating new objects and morphisms to the selected multi-model database."
                                   ),
                                html.Hr(),
                                html.Label(children=[
                                    html.
                                    H6("Visualize the selected object (includes results to queries): "
                                       ),
                                    dcc.Dropdown(
                                        id="select-visualized-object-dropdown",
                                        style={'width': '50%'},
                                        options=initial_options,
                                    )
                                ]),
                                html.Button(id="show-result-button",
                                            children="VISUALIZE"),
                                html.Hr(),
                                html.Div(id="main-result-container")
                            ])
                    ])
            ])
    ]
示例#15
0
def render_object_selection(n_clicks, domain, target):
    global parameter_state
    parameter_state["domain"] = domain
    parameter_state["target"] = target
    ctx = dash.callback_context
    prop_id = ""
    if ctx.triggered:
        prop_id = ctx.triggered[0]["prop_id"].split(".")[0]
        if prop_id == "submit-domain-target":
            if domain != None and target != None:
                database = multicategory.get_selected_multi_model_database()
                result = database.get_morphisms_for_pair_of_objects(
                    domain, target)
                return [o for o in result], {"display": "block"}
            else:
                raise PreventUpdate
        else:
            raise PreventUpdate
    else:
        raise PreventUpdate
示例#16
0
def execute_multi_model_join_first_phase(value):
    global parameter_state
    if value != None:
        db = multicategory.get_selected_multi_model_database()
        parameter_state["morphism"] = value
        result_model = db.get_objects()[parameter_state["domain"]].get_model()
        parameter_state["result_model"] = result_model
        lambda_function = db.get_morphisms(
        )[value].get_collection_relationship().get_lambda_function()
        code_lines = inspect.getsource(lambda_function)
        return [
            html.P(parameter_state["domain"] + " -- " + value + " --> " +
                   parameter_state["target"]),
            html.P("The result will be in " + result_model + " model."),
            html.
            P("The morphism is defined with the following lambda function: "),
            html.P(str(code_lines))
        ], {
            'display': 'block'
        }
    return [], {'display': 'none'}
示例#17
0
def update_return_attributes_graph(selected_domain):
    if selected_domain != None:
        data_object = multicategory.get_selected_multi_model_database(
        ).get_objects()[selected_domain]
        domain_model = data_object.get_model()
        attributes = data_object.get_attributes_from_model_category()
        if domain_model == "graph":

            vertices = [{
                'label': str(value),
                'value': str(value)
            } for value in attributes["vertices"]]
            edges = [{
                'label': str(value),
                'value': str(value)
            } for value in attributes["edges"]]
            return vertices, edges
        else:
            raise PreventUpdate
    else:
        raise PreventUpdate
示例#18
0
def build_instance_functor_tab():
    database = multicategory.get_selected_multi_model_database()
    G = database.get_instance_category_nx_graph()
    F = database.get_schema_category_nx_graph()
    instance_fig = nx_grah_to_cytoscape(G)
    schema_fig = nx_grah_to_cytoscape(F)
    return [
        html.Div(
            id="instance-functor-parent",
            children=[
                html.Div(
                    id="set-specs-intro-container",
                    children=[
                        html.
                        H5("The visualization of the schema and instance categories."
                           ),
                    ]),
                html.Div(id="schema-category",
                         children=[html.H6("Schema category"), schema_fig]),
                html.Div(id="instance-category",
                         children=[html.H6("Instance category"), instance_fig])
            ])
    ]
示例#19
0
def build_insert_query_subtab():
    objects = multicategory.get_selected_multi_model_database().get_objects()
    options = []
    for obj in objects:
        options.append({'label': str(obj), 'value': str(obj)})

    return [
        html.Div(id="insert-query-subtab-main-container",
                 children=[
                     html.Div(id="set-specs-intro-container",
                              children=[
                                  html.Label([
                                      "Select collection to insert",
                                      dcc.Dropdown(id="select-insert-dataset",
                                                   style={
                                                       'width': '90%',
                                                       "display": "block"
                                                   },
                                                   options=options)
                                  ]),
                                  html.Div(id="insert-tool")
                              ])
                 ])
    ]
示例#20
0
def build_selective_query_subtab():
    objects = multicategory.get_selected_multi_model_database().get_objects()
    initial_options = []
    examples = dict()
    for obj in objects:
        initial_options.append({'label': str(obj), 'value': str(obj)})
    with open(examples_path) as f:
        examples = json.load(f)[
            multicategory.get_selected_multi_model_database().get_name()]

    return [
        html.Div(
            id="query-tab-main-container",
            children=[
                html.Div(
                    id="set-specs-intro-container",
                    children=[
                        html.
                        H4("This area is for creating selective queries and creating new objects and morphisms to the selected multi-model database."
                           ),
                        html.Hr(),
                        html.Div(
                            id="folding-tool",
                            children=[
                                html.Div(
                                    id="fold-query-creator-title",
                                    style={
                                        "width": "100%",
                                        "display": "inline-block"
                                    },
                                    children=[
                                        html.
                                        H6("Create a new collection and morphism from the existing collection",
                                           style={'display': 'inline-block'}),
                                        html.Button(
                                            id=
                                            "learn-more-fold-function-button",
                                            children="LEARN MORE",
                                            style={"marginLeft": "10px"}),
                                        generate_fold_query_modal()
                                    ]),
                                html.Div(id="query-name",
                                         style={
                                             "border": "1px solid white",
                                             "padding": "10px",
                                             "margin": "10px"
                                         },
                                         children=[
                                             html.Label([
                                                 "Input name for this query",
                                                 html.Br(),
                                                 dcc.Input(
                                                     id="query-name-input",
                                                     type="text",
                                                     value="",
                                                     placeholder="name",
                                                     style={
                                                         'width': '90%',
                                                         "display": "block"
                                                     },
                                                 )
                                             ])
                                         ]),
                                html.Div(
                                    id="fold-query-creator",
                                    style={
                                        "width": "50%",
                                        "display": "inline-block",
                                        'float': 'left',
                                        "borderRight": "1px solid white"
                                    },
                                    children=[
                                        html.Div(
                                            id="fold-function-block",
                                            children=[
                                                html.Div(
                                                    style={
                                                        "border":
                                                        "1px solid white",
                                                        "padding": "10px",
                                                        "margin": "10px"
                                                    },
                                                    children=html.Label([
                                                        "Select queried domain dataset",
                                                        dcc.Dropdown(
                                                            id=
                                                            "select-query-domain-dataset",
                                                            style={
                                                                'width': '90%',
                                                                "display":
                                                                "block"
                                                            },
                                                            options=
                                                            initial_options,
                                                            disabled=False,
                                                        )
                                                    ])),
                                                html.Div(
                                                    id=
                                                    "filtering-condition-and-examples",
                                                    style={
                                                        "border":
                                                        "1px solid white",
                                                        "padding": "10px",
                                                        "margin": "10px"
                                                    },
                                                    children=[
                                                        html.Label([
                                                            "Input filtering condition for this block",
                                                            html.Br(),
                                                            dcc.Input(
                                                                id=
                                                                "lambda-function-input",
                                                                type="text",
                                                                value="",
                                                                placeholder=
                                                                "filtering condition",
                                                                style={
                                                                    'width':
                                                                    '90%',
                                                                    "display":
                                                                    "inline-block"
                                                                },
                                                            )
                                                        ]),
                                                        html.Br(),
                                                        html.Label([
                                                            "Examples",
                                                            html.Br(),
                                                            dcc.Dropdown(
                                                                id=
                                                                "filtering-example-dropdown",
                                                                style={
                                                                    'width':
                                                                    '90%',
                                                                    "display":
                                                                    "block"
                                                                },
                                                                options=
                                                                examples,
                                                            )
                                                        ])
                                                    ]),
                                                html.Div(
                                                    id=
                                                    "return-attribute-input-container",
                                                    style={
                                                        "border":
                                                        "1px solid white",
                                                        "padding": "10px",
                                                        "margin": "10px"
                                                    },
                                                    children=
                                                    render_return_attribute_input(
                                                        "relational",
                                                        fold_query_state)),
                                                html.Div(
                                                    style={
                                                        "border":
                                                        "1px solid white",
                                                        "padding": "10px",
                                                        "margin": "10px"
                                                    },
                                                    children=html.Label([
                                                        "Select target data model",
                                                        dcc.Dropdown(
                                                            id=
                                                            "select-target-data-model",
                                                            style={
                                                                'width': '90%',
                                                                "display":
                                                                "block"
                                                            },
                                                            options=[{
                                                                'label':
                                                                'relational',
                                                                'value':
                                                                'relational'
                                                            }, {
                                                                'label':
                                                                'property graph',
                                                                'value':
                                                                'graph'
                                                            }, {
                                                                'label':
                                                                'tree',
                                                                'value':
                                                                'tree'
                                                            }, {
                                                                'label':
                                                                'RDF graph',
                                                                'value':
                                                                'RDF'
                                                            }, {
                                                                'label':
                                                                'String',
                                                                'value':
                                                                'String'
                                                            }, {
                                                                'label':
                                                                'Int',
                                                                'value':
                                                                'Int'
                                                            }, {
                                                                'label':
                                                                'Boolean',
                                                                'value':
                                                                'Boolean'
                                                            }],
                                                            value='relational',
                                                        )
                                                    ])),
                                            ]),
                                        html.Br(),
                                        html.Button(
                                            id="append-query-block",
                                            children="APPEND QUERY BLOCK")
                                    ]),
                                html.Div(
                                    id="current-query-view",
                                    style={
                                        "width": "49%",
                                        "display": "inline-block",
                                        'float': 'left'
                                    },
                                    children=[
                                        html.H6("The current query: ",
                                                style={"margin": "5px"}),
                                        html.Div(
                                            id="current-query", children=[]),
                                        html.Button(
                                            id="execute-fold-query-button",
                                            children="EXECUTE",
                                            n_clicks=0,
                                            style={"marginLeft": "10px"}),
                                    ]),
                            ]),
                        html.Div(id="result-notification")
                    ])
            ])
    ]
示例#21
0
def build_multi_model_join_tab():
    objects = multicategory.get_selected_multi_model_database(
    ).get_str_list_of_objects()
    return [
        html.Div(
            id="set-specs-intro-container",
            children=[
                html.Div(
                    id="multi-model-join-parent-container",
                    style={"margin": "20px"},
                    children=[
                        html.Div(
                            id="multi-model-join-parameters-container",
                            children=[
                                html.Div(
                                    id="set-domain-intro-container",
                                    children=[
                                        html.
                                        P("Select the domain dataset for multi-model join."
                                          ),
                                        dcc.Dropdown(
                                            id="multi-model-join-domain",
                                            style={'width': '50%'},
                                            options=objects,
                                        ),
                                    ]),
                                html.Br(),
                                html.Div(
                                    id="set-target-intro-container",
                                    children=[
                                        html.
                                        P("Select the target dataset for multi-model join. Note that joins are done over morphisms. "
                                          ),
                                        dcc.Dropdown(
                                            id="multi-model-join-target",
                                            style={'width': '50%'},
                                            options=objects,
                                        ),
                                    ]),
                                html.Br(),
                                html.Button(id='submit-domain-target',
                                            children='Search morphisms'),
                                html.Div(
                                    id="hiding-element",
                                    style={"display": "none"},
                                    children=[
                                        html.Br(),
                                        html.Div(
                                            id="join-morphism-container",
                                            children=[
                                                html.
                                                P("If there does not exist a suitable morphism from the domain to the target, then you can create new one in the query tab."
                                                  ),
                                                dcc.Dropdown(
                                                    id=
                                                    "multi-model-join-morphisms",
                                                    style={'width': '50%'}),
                                            ]),
                                    ]),
                                html.Div(
                                    id="overall-join-hiding",
                                    style={'display': 'none'},
                                    children=[
                                        html.Br(),
                                        html.Div(
                                            id=
                                            "right-left-full-toggle-switches",
                                            children=[
                                                html.
                                                P("""You can choose left, right or full join. 
                        Left join is defined for all the data model combinations and the right join is defined between graphs. 
                        If the join is not avaible for the combination, the selection (ON/OFF) does not affect to the result. 
                        The idea behind left and right joins is not exactly the same as in the relational data model."""
                                                  ),
                                                daq.BooleanSwitch(
                                                    id='left-boolean-switch',
                                                    on=False,
                                                    persisted_props=['on']),
                                                html.Div(
                                                    id=
                                                    'left-boolean-switch-output'
                                                ),
                                                daq.BooleanSwitch(
                                                    id='right-boolean-switch',
                                                    on=False,
                                                    persisted_props=['on']),
                                                html.Div(
                                                    id=
                                                    'right-boolean-switch-output'
                                                )
                                            ]),
                                        html.Br(),
                                        html.Div(
                                            id="second_description_input"),
                                        html.Br(),
                                        html.Div(id="tree_attributes_input"),
                                        html.
                                        H5("The following multi-model join will be executed: "
                                           ),
                                        html.Div(id="overall-join"),
                                        html.Br(),
                                        html.Button(
                                            id='execute-button',
                                            children='Perform multi-model join'
                                        ),
                                    ]),
                            ]),
                        html.Div(id="multi-model-result-container")
                    ])
            ])
    ]