예제 #1
0
def relation_schema(schema, context, ignore_entities=False):
    relation = mapping('relation', validator=chained(source_not_target))
    relation.add(
        key('type', validator=chained(nonempty_string, in_([schema.name]))))
    if not ignore_entities:
        relation.add(_node(EntitySchemaType(context), 'source'))
        relation.add(_node(EntitySchemaType(context), 'target'))
    return apply_schema(relation, schema)
예제 #2
0
파일: entity.py 프로젝트: jmorenoamor/grano
def entity_schema(schema):
    entity = mapping('entity')
    entity.add(key('title', validator=chained(
            nonempty_string
        )))
    entity.add(key('type', validator=chained(
            nonempty_string,
            in_([schema.name])
        )))
    return apply_schema(entity, schema)
예제 #3
0
def relation_schema(schema, context, ignore_entities=False):
    relation = mapping('relation', validator=chained(
            source_not_target
        ))
    relation.add(key('type', validator=chained(
            nonempty_string,
            in_([schema.name])
        )))
    if not ignore_entities:
        relation.add(_node(EntitySchemaType(context), 'source'))
        relation.add(_node(EntitySchemaType(context), 'target'))
    return apply_schema(relation, schema)
예제 #4
0
def entity_schema(schema):
    entity = mapping('entity')
    entity.add(key('title', validator=chained(nonempty_string)))
    entity.add(
        key('type', validator=chained(nonempty_string, in_([schema.name]))))
    return apply_schema(entity, schema)
예제 #5
0
 def test_apply_schema(self):
     base = mapping('entity')
     schema = Schema.create(self.network, Schema.ENTITY, h.TEST_ENTITY_SCHEMA)
     base = apply_schema(base, schema)
     assert len(base.children)==len(h.TEST_ENTITY_SCHEMA['attributes'])
예제 #6
0
 def test_apply_schema(self):
     base = mapping('entity')
     schema = Schema.create(self.network, Schema.ENTITY,
                            h.TEST_ENTITY_SCHEMA)
     base = apply_schema(base, schema)
     assert len(base.children) == len(h.TEST_ENTITY_SCHEMA['attributes'])