Passed
Push — dependabot/pip/sphinx-copybutt... ( c72176 )
by
unknown
18:24 queued 16:24
created

mandos.analysis.reification.Reifier._reify_one()   A

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nop 2
dl 0
loc 12
rs 9.85
c 0
b 0
f 0
1
"""
2
Tool to export reified mandos triples.
3
"""
4
from typing import Generator, Sequence
5
6
from mandos.model.hits import AbstractHit, Triple
7
8
9
def _camelcase(s: str):
0 ignored issues
show
Coding Style Naming introduced by
Argument name "s" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
10
    return "".join(w.title() if i > 0 else w for i, w in enumerate(s.split("_")))
11
12
13
class Reifier:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
14
    def reify(self, hits: Sequence[AbstractHit]) -> Generator[Triple, None, None]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
15
        for hit in hits:
16
            yield from self._reify_one(hit)
17
18
    def _reify_one(self, hit: AbstractHit) -> Sequence[Triple]:
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
19
        uid = hit.universal_id
20
        state = Triple(uid, "rdf:type", "rdf:statement")
21
        pred = Triple(uid, "rdf:predicate", hit.predicate)
22
        obj = Triple(uid, "rdf:object", hit.object_name)
23
        exclude = {"origin_inchikey", "predicate"}
24
        others = [
25
            Triple(uid, "mandos:" + _camelcase(field), getattr(hit, field))
26
            for field in hit.fields()
27
            if field not in exclude
28
        ]
29
        return [state, pred, obj, *others]
30
31
32
__all__ = ["Reifier"]
33