| Conditions | 7 |
| Total Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # -*- coding: utf-8 -*- |
||
| 81 | def _add_metadataset(graph, subject, metadataset): |
||
| 82 | ''' |
||
| 83 | :param rdflib.graph.Graph graph: Graph that contains the Dataset. |
||
| 84 | :param rdflib.term.URIRef subject: Uri of the Dataset. |
||
| 85 | :param dict metadataset: Dictionary with metadata to add to the Dataset. |
||
| 86 | :rtype: :class:`rdflib.graph.Graph` |
||
| 87 | ''' |
||
| 88 | mapping = { |
||
| 89 | 'creator': { |
||
| 90 | 'predicate': DCTERMS.creator, |
||
| 91 | 'objecttype': URIRef |
||
| 92 | }, |
||
| 93 | 'publisher': { |
||
| 94 | 'predicate': DCTERMS.publisher, |
||
| 95 | 'objecttype': URIRef |
||
| 96 | }, |
||
| 97 | 'contributor': { |
||
| 98 | 'predicate': DCTERMS.contributor, |
||
| 99 | 'objecttype': URIRef |
||
| 100 | }, |
||
| 101 | 'language': { |
||
| 102 | 'predicate': DCTERMS.language |
||
| 103 | }, |
||
| 104 | 'date': { |
||
| 105 | 'predicte': DCTERMS.date |
||
| 106 | }, |
||
| 107 | 'created': { |
||
| 108 | 'predicate': DCTERMS.created |
||
| 109 | }, |
||
| 110 | 'issued': { |
||
| 111 | 'predicate': DCTERMS.issued |
||
| 112 | }, |
||
| 113 | 'license': { |
||
| 114 | 'predicate': DCTERMS.license, |
||
| 115 | 'objecttype': URIRef |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | for k, v in mapping.items(): |
||
| 120 | if k in metadataset: |
||
| 121 | if 'objecttype' in v: |
||
| 122 | objecttype = v['objecttype'] |
||
| 123 | else: |
||
| 124 | objecttype = Literal |
||
| 125 | for ko in metadataset[k]: |
||
| 126 | if objecttype == Literal: |
||
| 127 | if 'datatype' in v: |
||
| 128 | o = Literal(ko, datatype=v['datatype']) |
||
| 129 | else: |
||
| 130 | o = Literal(ko) |
||
| 131 | else: |
||
| 132 | o = objecttype(ko) |
||
| 133 | graph.add((subject, v['predicate'], o)) |
||
| 134 | return graph |
||
| 135 |