Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature #45 new schema for OCDS #46

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/popit_relationship/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import networkx as nx
from networkx.exception import NetworkXError

from popit_relationship.schema.base import Namespace, Schema

CACHE_PATH_DEFAULT = "./primport-cache.gpickle"
KEY_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
KEY_RELATIONSHIP = "http://purl.org/vocab/relationship/Relationship"
Expand Down Expand Up @@ -51,3 +53,7 @@ def node_get_type(graph, node):
return [j for i, j, k in graph.edges if i == node and k == KEY_TYPE][0]
except IndexError:
return False


def schema_generate_uri(namespace: Namespace, schema: Schema):
return f"{namespace.__class__.BASE.value}{namespace.value}#{schema.value}"
9 changes: 9 additions & 0 deletions src/popit_relationship/schema/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from enum import Enum


class Namespace(Enum):
pass


class Schema(Enum):
pass
33 changes: 33 additions & 0 deletions src/popit_relationship/schema/sinar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from popit_relationship.schema.base import Namespace, Schema


class Ownership(Schema):
OWNERSHIP_OR_CONTROL_STATEMENT = "ownershipOrControlStatement"


class OCDS(Schema):
"""
Types
"""

EXTRACTIVE_CONCESSION = "extractiveConcession"
ORGANIZATION = "organization"

"""
Relationships
"""
BUYER = "buyer"
PROCURING_ENTITY = "procuringEntity"
ADMINISTRATIVE_ENTITY = "administrativeEntity"
TENDERER = "tenderer"
SUPPLIER = "supplier"
FUNDER = "funder"
REVIEW_BODY = "reviewBody"
INTERESTED_PARTY = "interestedParty"


class Sinar(Namespace):
BASE = "https://sinarproject.org/ns/"

OWNERSHIP = "ownership"
OCDS = "ocds"
19 changes: 13 additions & 6 deletions src/popit_relationship/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@
from loguru import logger
from toolz.dicttoolz import get_in, valfilter

from popit_relationship.common import coro, graph_init, graph_prune, graph_save
from popit_relationship.common import (
coro,
graph_init,
graph_prune,
graph_save,
schema_generate_uri,
)
from popit_relationship.schema.sinar import Ownership, Sinar

TYPE_PERSON = "https://www.w3.org/ns/person#Person"
TYPE_POST = "http://www.w3.org/ns/org#Post"
TYPE_ORGANIZATION = "http://www.w3.org/ns/org#Organization"
TYPE_MEMBERSHIP = "http://www.w3.org/ns/org#Membership"
TYPE_RELATIONSHIP = "http://purl.org/vocab/relationship/Relationship"

SINAR_NS_MOCK = "https://sinarproject.org/ns/ownership#"


@click.group()
def sync():
Expand All @@ -35,7 +40,7 @@ async def all_sync(_ctx):
await tree_import(TYPE_POST, "Post", post_build_node)
await tree_import(TYPE_MEMBERSHIP, "Membership", membership_build_node)
await tree_import(
f"{SINAR_NS_MOCK}ownershipOrControlStatement",
schema_generate_uri(Sinar.OWNERSHIP, Ownership.OWNERSHIP_OR_CONTROL_STATEMENT),
"Ownership Control Statement",
ownership_build_node,
)
Expand Down Expand Up @@ -103,7 +108,7 @@ def membership_build_node(membership):
@coro
async def ownership():
await tree_import(
f"{SINAR_NS_MOCK}ownershipOrControlStatement",
schema_generate_uri(Sinar.OWNERSHIP, Ownership.OWNERSHIP_OR_CONTROL_STATEMENT),
"Ownership Control Statement",
ownership_build_node,
)
Expand All @@ -117,7 +122,9 @@ def ownership_build_node(ownership):
{
"subject": get_in(["interestedParty", "@id"], ownership, None),
"predicate": {
"key": f"{SINAR_NS_MOCK}ownershipOrControlStatement",
"key": schema_generate_uri(
Sinar.OWNERSHIP, Ownership.OWNERSHIP_OR_CONTROL_STATEMENT
),
"attributes": predicate_attribute_filter_empty(
{
"interest_level": get_in(
Expand Down