goblin.provider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Provider.get_default_op_args() 0 3 1
A TinkerGraph.get_hashable_id() 0 3 1
A JanusGraph.get_hashable_id() 0 14 5
1
from typing import Dict, Any
2
3
class Provider:
4
    """Superclass for provider plugins"""
5
    DEFAULT_OP_ARGS: Dict[Any, Any] = {}
6
7
    @classmethod
8
    def get_default_op_args(cls, processor):
9
        return cls.DEFAULT_OP_ARGS.get(processor, dict())
10
11
12
class TinkerGraph(Provider):  # TODO
13
    """Default provider"""
14
15
    @staticmethod
16
    def get_hashable_id(val):
17
        return val
18
19
class JanusGraph(Provider):  # TODO
20
    """Default provider"""
21
22
    @staticmethod
23
    def get_hashable_id(val):
24
        if not isinstance(val, dict):
25
            return val
26
        type_prop = val.get("@type", None)
27
        if not type_prop == "janusgraph:RelationIdentifier":
28
            return val
29
        val_prop = val.get("@value", None)
30
        if not isinstance(val_prop, dict):
31
            return val
32
        rel_prop = val_prop.get("relationId", None)
33
        if not rel_prop:
34
            return val
35
        return rel_prop
36
37