Esempio n. 1
0
 def _regulate(self, job, graph):
     try:
         Regulator(job).regulate(graph)
         return graph
     except exceptions.RegulateError as e:
         job.fail(e)
         return None
Esempio n. 2
0
def accept_changes(context, nodes, username):
    user = models.ShareUser.objects.get(username=username)
    graph = MutableGraph.from_jsonld(nodes)
    Regulator().regulate(graph)
    nd = NormalizedDataFactory(source=user)
    change_set = ChangeSetBuilder(graph, nd, disambiguate=True).build_change_set()
    return change_set.accept() if change_set else None
Esempio n. 3
0
 def _regulate(self, job, graph):
     try:
         Regulator(job).regulate(graph)
     except exceptions.RegulateError as e:
         job.fail(e)
         return None
     job.log_graph('regulated_datum', graph)
     return graph
Esempio n. 4
0
 def run_transformer(config, id, datum):
     transformer = config.get_transformer()
     with launch_ipdb_on_exception():
         graph = transformer.transform(datum)
         if args.get('--regulate'):
             Regulator(source_config=config).regulate(graph)
         print('Parsed raw data "{}" into'.format(id))
         pprint(graph.to_jsonld(in_edges=False))
         print('\n')
Esempio n. 5
0
 def test_calls_steps(self, steps, num_nodes):
     graph = MutableGraph()
     for i in range(num_nodes):
         graph.add_node(i, 'creativework')
     Regulator().regulate(graph)
     assert all(m.should_regulate.call_count == num_nodes for m in steps['node'])
     assert all(m.regulate_node.call_count == num_nodes for m in steps['node'])
     assert all(m.regulate_graph.call_count == 1 for m in steps['graph'])
     assert all(m.validate_graph.call_count == 1 for m in steps['validation'])
Esempio n. 6
0
    def _ingest(graph, disambiguate=True, regulate=True, user=None, save=True):
        if regulate:
            Regulator().regulate(graph)

        nd = factories.NormalizedDataFactory(
            source=user) if user else normalized_data
        cs = ChangeSetBuilder(graph, nd,
                              disambiguate=disambiguate).build_change_set()
        if save and cs is not None:
            cs.accept()
        return cs
Esempio n. 7
0
    def test_get_data(self, generator, model, route, controlled_values, client,
                      Graph, ingest):
        ingest(Graph(initial))

        graph = Graph(*generator)
        Regulator().regulate(graph)
        matches = Matcher(DatabaseStrategy()).find_all_matches(graph)

        for node in graph:
            if node.type == model:
                expected = node
                expected_id = IDObfuscator.encode(matches[node])
                break
        response = client.get('/api/v2/{}/{}/'.format(route, expected_id))

        actual = json.loads(response.content.decode(encoding='UTF-8'))

        assert response.status_code == 200
        assert actual['data']['id'] == expected_id
        assert actual['data']['attributes']['type'] == expected.type
        for value in controlled_values:
            assert actual['data']['attributes'][value] == expected[
                camelCase_to_underscore(value)]
Esempio n. 8
0
 def test_normalize_tags_on_work(self, input, output, Graph, ExpectedGraph):
     graph = Graph(CreativeWork(tags=input))
     Regulator(validate=False).regulate(graph)
     assert graph == ExpectedGraph(CreativeWork(tags=output))
Esempio n. 9
0
 def test_normalize_agentworkrelation(self, input, output, Graph,
                                      ExpectedGraph):
     graph = Graph(input)
     Regulator(validate=False).regulate(graph)
     assert graph == ExpectedGraph(output)
Esempio n. 10
0
 def test_normalize_contributor_creator_relation(self, input, output, Graph,
                                                 ExpectedGraph):
     graph = Graph(CreativeWork(agent_relations=input))
     Regulator(validate=False).regulate(graph)
     assert graph == ExpectedGraph(CreativeWork(agent_relations=output))
Esempio n. 11
0
 def test_normalize_organization_institution_name(self, input, output,
                                                  Graph, ExpectedGraph):
     graph = Graph(*input)
     Regulator(validate=False).regulate(graph)
     assert graph == ExpectedGraph(*output)
Esempio n. 12
0
 def test_normalize_person_relation(self, input, output, Graph,
                                    ExpectedGraph):
     graph = Graph(*input)
     Regulator(validate=False).regulate(graph)
     assert graph == ExpectedGraph(*output)