Browse Source

[ENH] Add the AnchoredMarket

tags/v0.3.2
Gene 2 years ago
parent
commit
e84a8cd830
2 changed files with 62 additions and 14 deletions
  1. +56
    -9
      learnware/market/anchor.py
  2. +6
    -5
      learnware/market/base.py

+ 56
- 9
learnware/market/anchor.py View File

@@ -53,28 +53,75 @@ class AnchoredMarket(BaseMarket):
def __init__(self):
super(AnchoredMarket, self).__init__()
self.anchor_learnware_list = {} # anchor_id: anchor learnware
def get_anchor_learnware(self, user_info: AnchoredUserInfo) -> Tuple[Any, Dict[str, List[Any]]]:
"""Get anchor Learnware based on user_info
def _update_anchor_learnware(self, anchor_id: str, anchor_learnware: Learnware):
"""Update anchor_learnware_list

Parameters
----------
anchor_id : str
Id of anchor learnware
anchor_learnware : Learnware
Anchor learnware
"""
self.anchor_learnware_list[anchor_id] = anchor_learnware
def _delete_anchor_learnware(self, anchor_id: str) -> bool:
"""Delete anchor learnware in anchor_learnware_list

Parameters
----------
anchor_id : str
Id of anchor learnware

Returns
-------
bool
True if the target anchor learnware is deleted successfully.
Raises
------
Exception
Raise an excpetion when given anchor_id is NOT found in anchor_learnware_list
"""
if not anchor_id in self.anchor_learnware_list:
raise Exception("Anchor learnware id:{} NOT Found!".format(anchor_id))

self.anchor_learnware_list.pop(anchor_id)
return True
def update_anchor_learnware_list(self, learnware_list: Dict[str, Learnware]):
"""Update anchor_learnware_list

Parameters
----------
learnware_list : Dict[str, Learnware]
Learnwares for updating anchor_learnware_list
"""
pass
def search_anchor_learnware(self, user_info: AnchoredUserInfo) -> Tuple[Any, List[Learnware]]:
"""Search anchor Learnwares from anchor_learnware_list based on user_info

Parameters
----------
user_info : AnchoredUserInfo
- user_info with properties and statistical information
- some statistical information calculated on anchor learnwares
- some statistical information calculated on previous anchor learnwares

Returns
-------
Tuple[Any, Dict[str, List[Any]]]
Tuple[Any, List[Learnware]]:
return two items:

- first is recommended combination, None when no recommended combination is calculated or statistical specification is not provided.
- second is a list of matched learnwares
- first is the usage of anchor learnwares, e.g., how to use anchors to calculate some statistical information
- second is a list of anchor learnwares
"""
pass
def search_learnware(self, user_info: AnchoredUserInfo) -> Tuple[Any, Dict[str, List[Any]]]:
"""Search learnware based on user_info
def search_learnware(self, user_info: AnchoredUserInfo) -> Tuple[Any, List[Learnware]]:
"""Find helpful learnwares from learnware_list based on user_info

Parameters
----------
@@ -84,7 +131,7 @@ class AnchoredMarket(BaseMarket):

Returns
-------
Tuple[Any, Dict[str, List[Any]]]
Tuple[Any, List[Any]]
return two items:

- first is recommended combination, None when no recommended combination is calculated or statistical specification is not provided.


+ 6
- 5
learnware/market/base.py View File

@@ -109,7 +109,7 @@ class BaseMarket:
A flag indicating whether the learnware can be accepted.
"""
return True
def add_learnware(
self, learnware_name: str, model_path: str, stat_spec_path: str, property: dict, desc: str
) -> Tuple[str, bool]:
@@ -187,8 +187,7 @@ class BaseMarket:
return None

def delete_learnware(self, id: str) -> bool:
"""
deleted a learnware from market
"""Delete a learnware from market

Parameters
----------
@@ -203,10 +202,12 @@ class BaseMarket:
Raises
------
Exception
Raise an excpetion when give id is NOT found in learnware list
"""
Raise an excpetion when given id is NOT found in learnware list
"""
if not id in self.learnware_list:
raise Exception("Learnware id:{} NOT Found!".format(id))

self.learnware_list.pop(id)
return True

def update_learnware(self, id: str) -> bool:


Loading…
Cancel
Save