flarebyte/bubblegum-entity/1.1.1

Bubblegum.Entity.Attribute

An attribute represents a small piece of information such as a Semantic triple.

Model setters

type alias Model =
{ id : Maybe String
, key : String
, values : List String
, facets : List String
}

The core representation of an attribute with:

  • id: a possible id to represent the attribute (ex: id:1234)
  • key: the key of the attribute (ex: ui:label)
  • values: a list of string values
  • facets: an optional list of tags to mark the data (ex: [min])

When representing a RDF triple:

  • subject: should be represented by id
  • predicate: should be represented by key
  • object: should be represented by values
setId : Maybe String -> Model -> Model

Set a possible id to represent the attribute

 setId (Just "id:1234") model
setKey : String -> Model -> Model

Set the key of the attribute

setKey "ui:label" model
setValues : List String -> Model -> Model

Set a list of string values

setValues [ "some label" ] model
setFacets : List String -> Model -> Model

Set an optional list of tags to mark the data

setFacets [ "min", "inclusive" ] model

Attribute

findAttributeByKey : String -> List Model -> Maybe Model

Find an attribute by key

findAttributeByKey "ui:label" models -- Just label
findAttributeFirstValueByKey : String -> List Model -> Maybe String

Find an attribute by key and then get the first value if any

findAttributeFirstValueByKey "ui:label" models -- Just "some label"
replaceAttributeByKey : String -> List String -> List Model -> List Model

Replace or create an attribute by key

 replaceAttributeByKey "ui:label" ["new label"] models -- models
deleteAttributeByKey : String -> List Model -> List Model

Delete an attribute by key

deleteAttributeByKey "ui:label" models -- []

Outcome

findOutcomeByKey : String -> List Model -> Outcome (List String)

Find an outcome searching by key

findOutcomeByKey "ui:label" models -- Valid ["some label"]
( String, String )
-> List Model
-> Outcome ( List String, List String )

Find an outcome searching by a couple of keys

findOutcomeByKeyTuple ( "ui:min", "ui:max" ) models -- Valid (["1"], ["10"])