add type hints
This commit is contained in:
parent
fda1579a87
commit
7a4285c053
@ -1,3 +1,4 @@
|
|||||||
|
from typing import List
|
||||||
from itertools import product
|
from itertools import product
|
||||||
|
|
||||||
visibility = ('bad', 'medium', 'good')
|
visibility = ('bad', 'medium', 'good')
|
||||||
@ -9,7 +10,7 @@ pressure_gt_two = (True, False)
|
|||||||
attributes = ['visibility', 'stability', 'ground', 'mine_type', 'armed', 'pressure_gt_two']
|
attributes = ['visibility', 'stability', 'ground', 'mine_type', 'armed', 'pressure_gt_two']
|
||||||
|
|
||||||
|
|
||||||
def generate_data_set():
|
def generate_data_set() -> List[dict]:
|
||||||
data_list = list(product(visibility, stability, ground, mine_type, armed, pressure_gt_two))
|
data_list = list(product(visibility, stability, ground, mine_type, armed, pressure_gt_two))
|
||||||
data = [
|
data = [
|
||||||
{
|
{
|
||||||
|
@ -60,7 +60,7 @@ def tree_learn(examples: List[Dict], attributes: List[str], default_class: str)
|
|||||||
return root
|
return root
|
||||||
|
|
||||||
|
|
||||||
def get_decision(data, root):
|
def get_decision(data: dict, root: Node) -> str:
|
||||||
while root.children:
|
while root.children:
|
||||||
for children in root.children:
|
for children in root.children:
|
||||||
if data[root.name] == children.edge:
|
if data[root.name] == children.edge:
|
||||||
|
21
src/tile.py
21
src/tile.py
@ -2,13 +2,20 @@ from typing import Union
|
|||||||
|
|
||||||
from ap_mine import APMine
|
from ap_mine import APMine
|
||||||
from at_mine import ATMine
|
from at_mine import ATMine
|
||||||
|
from adm_mine import ADMMine
|
||||||
|
|
||||||
|
|
||||||
class Tile:
|
class Tile:
|
||||||
def __init__(self, number: int, weight: int, visibility, stability, ground, mine: Union[None, APMine, ATMine] = None):
|
def __init__(self,
|
||||||
self.number = number
|
number: int,
|
||||||
self.mine = mine
|
weight: int,
|
||||||
self.weight = weight
|
visibility: str,
|
||||||
self.visibility = visibility
|
stability: str,
|
||||||
self.stability = stability
|
ground: str,
|
||||||
self.ground = ground
|
mine: Union[None, APMine, ATMine, ADMMine] = None):
|
||||||
|
self.number = number
|
||||||
|
self.mine = mine
|
||||||
|
self.weight = weight
|
||||||
|
self.visibility = visibility
|
||||||
|
self.stability = stability
|
||||||
|
self.ground = ground
|
||||||
|
Loading…
Reference in New Issue
Block a user