Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
KWH40
fml40-reference-implementation
Commits
09cd2354
Commit
09cd2354
authored
Dec 02, 2020
by
GromeTT
Browse files
ENH: Added documentation for feature.py
parent
1bf14912
Changes
1
Hide whitespace changes
Inline
Side-by-side
ml/feature.py
View file @
09cd2354
from
ml.identifier
import
ID
"""This module implements the Feature class according to the forest
modeling language 4.0."""
import
sys
from
abc
import
ABC
import
os
from
abc
import
ABC
from
ml.identifier
import
ID
class
Feature
(
ABC
):
"""The Feature class represents the base class for all functionalities
and values."""
def
__init__
(
self
,
name
=
""
,
identifier
=
""
):
"""Constructs a new Feature class object with the given name and
identifier.
:param name: Name of the feature
:param identifier: Identifier of the feature
"""
self
.
__name
=
name
# TODO: Move setup code of __class_name into the correct setter method.
if
'ml
\\
fml40'
in
sys
.
modules
[
self
.
__class__
.
__module__
].
__file__
:
self
.
__class_name
=
"fml40::{}"
.
format
(
self
.
__class__
.
__name__
)
else
:
...
...
@@ -16,38 +30,100 @@ def __init__(self, name="", identifier=""):
@
property
def
class_name
(
self
):
"""Adds the prefix ml40:: to the class name and returns it.
:returns: Name of this object's class
:rtype: str
"""
return
self
.
__class_name
@
class_name
.
setter
def
class_name
(
self
,
value
):
"""Sets __class_name to value.
:param value: New class name
"""
# !!! What about the namespace?
# ??? Do we really need to have this function?
# Can't this be done implicitly?
self
.
__class_name
=
value
@
property
def
name
(
self
):
"""Returns the object's name.
:returns: Name of the object
:rtype: str
"""
return
self
.
__name
@
name
.
setter
def
name
(
self
,
value
):
"""Sets __name to value.
:param value: New name
"""
self
.
__name
=
value
@
property
def
identifier
(
self
):
"""Returns the object's indentifier.
:returns: Identifier
:rtype: str
"""
return
self
.
__identifier
@
identifier
.
setter
def
identifier
(
self
,
value
):
self
.
__identifier
=
ID
(
value
).
identifier
"""Builds an ID object from value and assigns the resulting identifier
to __identifier.
:param value: Proposal of the identifier
"""
self
.
__identifier
=
ID
(
value
).
identifier
@
property
def
subFeatures
(
self
):
"""Returns a dict containing all subordinate features.
:returns: All subordinate features.
:rtype: dict[<str>, <Feature>]
"""
return
self
.
__subFeatures
@
subFeatures
.
setter
def
subFeatures
(
self
,
value
):
"""Replaces __subFeatures with value.
:param value: New collection of subordinate features
"""
# !!! Do we really want this? Better add and remove functions.
self
.
__subFeatures
=
value
def
to_json
(
self
):
"""Returns a json representation of this feature. Note that this
function works recursively.
:returns: Json representation
:rtype: str
"""
self
.
__json_out
=
{
"class"
:
self
.
class_name
,
"identifier"
:
self
.
identifier
,
...
...
@@ -57,6 +133,6 @@ def to_json(self):
if
self
.
subFeatures
:
self
.
__json_out
[
"subFeatures"
]
=
list
()
for
key
in
self
.
subFeatures
.
keys
():
self
.
__json_out
[
"subFeatures"
].
append
(
self
.
subFeatures
[
key
].
to_json
())
res
=
self
.
subFeatures
[
key
].
to_json
()
self
.
__json_out
[
"subFeatures"
].
append
(
res
)
return
self
.
__json_out
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment