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)
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)
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)
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)
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'])
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'])