Config proposal (API Simplification)

Open
#84 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python

Research direction

Start by reviewing issue #83 and the current SDK configuration/API entry points; this proposal introduces Feature, Category, Text, Number, and Schema. Compare the existing API with the shown JSON output and clarify the intended simplification with maintainers. Done means the design is agreed and its implementation scope is defined.

Written by the indexing model from the issue text.

Description

This is number 3 from #83 , @mhaas , what do you think?

import json
class Feature:
    def __init__(self,columns:list=[]):
        self.columns = columns
        self.repr = self._get_def()
    @property
    def featuretype(self):
        pass
    def _get_def(self):
        cols = []
        for col in self.columns:
            cols.append({"label": col, "type": self.featuretype})
        return cols
    def __add__(self,other):
        self.repr=self.repr+other.repr
        return self
    def __repr__(self):
        return str(self.repr)

class Category(Feature):
    def __init__(self,columns:list=[]):
        super(Category,self).__init__(columns)
    @property
    def featuretype(self):
        return "CATEGORY"
    
class Text(Feature):
    def __init__(self,columns:list=[]):
        super(Text,self).__init__(columns)
    @property
    def featuretype(self):
        return "TEXT"

class Number(Feature):
    def __init__(self,columns:list=[]):
        super(Number,self).__init__(columns)
    @property
    def featuretype(self):
        return "NUMBER"

class Schema:
    def __init__(self,features=None,labels=None,name=None):
        self.features = features
        self.labels = labels
        self.name = name
        self.repr = self._get_def()
    def _get_def(self):
        return json.dumps({
                            "features": self.features.repr,
                            "labels": self.labels.repr,
                            "name": self.name,
                            },indent=2)
    def __repr__(self):
        return str(self.repr)

features = Text(['MYTEXT'])+Number(['ANumeric'])+Category(['Manufacturee','description'])
labels = Category(['Label1','Label2'])+Number(['Label3'])
schema = Schema(features,labels,"bestbuy-category-prediction")
print(schema)

result:
{
"features": [
{
"label": "MYTEXT",
"type": "TEXT"
},
{
"label": "ANumeric",
"type": "NUMBER"
},
{
"label": "Manufacturee",
"type": "CATEGORY"
},
{
"label": "description",
"type": "CATEGORY"
}
],
"labels": [
{
"label": "Label1",
"type": "CATEGORY"
},
{
"label": "Label2",
"type": "CATEGORY"
}
],
"name": "bestbuy-category-prediction"
}

Dominant language
Jupyter Notebook
Stars
20
Forks
6
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SAP/data-attribute-recommendation-python-sdk

All issues in SAP/data-attribute-recommendation-python-sdk

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.