reqt intro

Upload: ravirajrbk

Post on 14-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 ReqT Intro

    1/41

    Introduction to reqT- a free software requirements modeling tool

    reqT.org

    LundUniversity.lu.se

    Last changed: Feb 13, 2013

  • 7/30/2019 ReqT Intro

    2/41

    What can you do with reqT?

    You can ...

    create & manage scalable requirements models

    using versatile collections

    combine natural language expressivenesswith type-safe modeling

    interoperate with spread sheet applications

    auto-generate requirements documents

    for web publishing

    do powerful scripting of requirements models

    with the reqT internal Scala DSL

    http://en.wikipedia.org/wiki/Collection_(abstract_data_type)http://en.wikipedia.org/wiki/Type_safetyhttp://en.wikipedia.org/wiki/Scala_(programming_language)http://en.wikipedia.org/wiki/Scala_(programming_language)http://en.wikipedia.org/wiki/Type_safetyhttp://en.wikipedia.org/wiki/Collection_(abstract_data_type)
  • 7/30/2019 ReqT Intro

    3/41

    reqT Gist

    var m = Model(Product("reqT") has

    Gist("A tool for modeling evolving requirements."),

    Release("2.0") has

    Gist("Major update based on student feedback."),Product("reqT") owns Release("2.0")

    )

    m += Feature("toHtml") has Gist("Generate web document.")

    println(m)

    m.toHtml.save("reqT.html")

  • 7/30/2019 ReqT Intro

    4/41

    Feature("toHtml")

  • 7/30/2019 ReqT Intro

    5/41

    Create your own document templates

    val myTemplate = DocumentTemplate(

    "Requirements Document",

    Text("Generated by " +

    " reqT.org " +

    ( new java.util.Date ) ),

    Chapter("Context", Text(""), m => m / Context),

    Chapter("Features", Text(""), m => m / Feature)

    )

    m.toHtml(myTemplate).save("reqT.html")

  • 7/30/2019 ReqT Intro

    6/41

    Feature("toTable")

    Model.fromTable("reqT.txt")

  • 7/30/2019 ReqT Intro

    7/41

    How to run reqT

    You can run reqT in several ways:

    Kojo - an interactive environment for Scala

    scripting http://kogics.net/sf:kojo

    Scala REPL command line Read-Evaluate-

    Print-Loop http://typesafe.com/stack

    In your own pre-compiled Scala applicationFor more details on how to download & install

    reqT into Kojo or Scala, see reqT.org/download

    http://kogics.net/sf:kojohttp://typesafe.com/stackhttp://reqt.org/downloadhttp://reqt.org/downloadhttp://typesafe.com/stackhttp://kogics.net/sf:kojo
  • 7/30/2019 ReqT Intro

    8/41

    Why is reqT built in Scala?

    Platform-independent and efficient (JVM)

    Flying start if you know some Java

    Statically typed: help to locate bugs early

    Statically typed: fast and efficient programs

    Type inference: less verbose

    Flexible syntax: good for internal DSL

    Interactive scripting: rapid trialing & feedback

    Scalability: from small scripts to large systems

    Free open source, academic control (EPFL), EUsupport with commercial backup (typesafe.com )

    http://en.wikipedia.org/wiki/Scala_(programming_language)http://en.wikipedia.org/wiki/Java_virtual_machinehttp://en.wikipedia.org/wiki/Java_(programming_language)http://en.wikipedia.org/wiki/Domain-specific_languagehttp://www.scala-lang.org/node/8579http://www.scala-lang.org/node/8579http://typesafe.com/http://typesafe.com/http://typesafe.com/http://typesafe.com/http://www.scala-lang.org/node/8579http://typesafe.com/http://typesafe.com/http://www.scala-lang.org/node/8579http://www.scala-lang.org/node/8579http://en.wikipedia.org/wiki/Martin_Oderskyhttp://en.wikipedia.org/wiki/Domain-specific_languagehttp://en.wikipedia.org/wiki/Java_(programming_language)http://en.wikipedia.org/wiki/Java_virtual_machinehttp://en.wikipedia.org/wiki/Scala_(programming_language)
  • 7/30/2019 ReqT Intro

    9/41

    Modeling requirements with reqT

    A reqT model includes sequences of graph parts

    separated by comma and wrapped inside a Model( )

    A small reqT Model with Entities (three Features oneStakeholder) and Edges (has, requires, assigns) and related setsof nodes (either attributes or other entities):

    Model(

    Feature("f1") has (Spec("A good spec."), Status(SPECIFIED)),

    Feature("f1") requires (Feature("f2"), Feature("f3")),

    Stakeholder("s1") assigns(Prio(1)) to Feature("f2")

    )

  • 7/30/2019 ReqT Intro

    10/41

    Implied reqT graph structure

    Feature

    ("f1")

    Feature

    ("f2")

    requires

    Stakeholder("s1")

    assigns(Prio(1))

    Feature

    ("f3")

    requires

    Status

    Spec

    has

    has

    Model(Feature("f1") has (Spec("A good spec."), Status(SPECIFIED)),Feature("f1") requires (Feature("f2"), Feature("f3")),Stakeholder("s1") assigns(Prio(1)) to Feature("f2")

    )

  • 7/30/2019 ReqT Intro

    11/41

    Different types of Requirement entities in reqT

    Requirement

    Feature

    UserStory

    Goal

    UseCase

    TaskScenario

    VividScenario

    Function

    Data

    Quality

    Interface

    Design

    Class

    Member

  • 7/30/2019 ReqT Intro

    12/41

    Different types of Context entities in reqT

    Context

    Product

    Release

    Stakeholder

    Actor

  • 7/30/2019 ReqT Intro

    13/41

    Different types of Relations in reqT

    Relation owns

    excludes

    assigns(Attribute)

    precedes

    inherits

    requires

    helps

    hurts

    deprecates

    Special relationship

    for hierarchical

    decomposition

  • 7/30/2019 ReqT Intro

    14/41

    Expressing interdependencies in reqT An and-relation is equivalent to two mutual requires-relations:

    Feature("printer.X") requires Feature("driver.Y")Feature("driver.Y") requires Feature("printer.X")

    Sometimes a requires-relation is non-mutual:

    Feature("sendEmail") requires Feature("networkAccess")

    Temporal relations regarding a preferred implementation order can be expressed using aprecedes-relation:

    Function("add") precedes Function("delete")

    Mutual exclusion (xor) can be expressed using two mutual excludes-relations:

    Design("centralized") excludes Design("distributed")

    Design("distributed") excludes Design("centralized")

    Entities that support or hinder each other are modeled using hurts and helps relations :

    Goal("secure") helps Goal("safe")

    Goal("secure") hurts Goal("simple")

    [Some examples modified from Carlshamre, P., Sandahl, K., Lindvall, M., Regnell, B., Natt och Dag: "An industrial survey of requirements interdependencies in

    software product release planning", J.: Int. Conf. on Requirements Engineering (RE01), Toronto, Canada, pp. 8491, 2001]

  • 7/30/2019 ReqT Intro

    15/41

    Expressing release allocation in reqT

    The result of release planning can be expressed in reqT usingrequires-relations between Release and Requirement entities:

    Model(

    Product("p") owns (Release("A"), Release("B"), Release("C")),

    Release("A") precedes Release("B"),

    Release("B") precedes Release("C"),

    Release("A") requires (Feature("a"),Feature("b"),Feature("c")),

    Release("B") requires (Feature("d"),Feature("e"),Feature("f"))

    )

    Future versions of reqT may include constraints to formulateand solve release planning problems using ConstraintSatisfaction Programming (CSP) with a CSP solver (e.g. JaCoP)

  • 7/30/2019 ReqT Intro

    16/41

    Different types of Attributes in reqTAttribute[T](value: T)

    Spec(String)

    Gist(String)

    Status(Level)

    Why(String)

    Example(String)

    Input(String)

    Output(String)

    Trigger(String)

    Precond(String)

    Frequency(String)

    Critical(String)

    Problem(String)

    Prio(Int)

    Label(String)

    Image(String)Comment(String)

    Deprecated(String)

  • 7/30/2019 ReqT Intro

    17/41

    reqT.Goal example

    Goals are high-level reasons for creating products or features.

    Model(

    Product("shipyard quoting") hasSpec("Ship repair cost calculations based on experience data."),

    Goal("increase accuracy") has

    Spec("Our precalculations shall be more accurate than today."),

    Product("shipyard quoting") helps Goal("increase accuracy")

    )

    [Example modified from Lauesen: "Software Requirements Styles and Techniques"]

  • 7/30/2019 ReqT Intro

    18/41

    reqT.Feature example

    A feature is a releasable characteristic of a Product.

    Model(

    Feature("room repair") has (

    Gist("Manage room repair periods."),

    Spec("The product shall be able to " +

    "record that a room is under repair in a specified period." +

    "When under repair, the room shall not be bookable."),

    Status(SPECIFIED)

    )

    )

    [Example modified from Lauesen: "Software Requirements Styles and Techniques"]

  • 7/30/2019 ReqT Intro

    19/41

    reqT.org

    Status promotion levels

    SPECIFIED

    ELICITED

    VALIDATED

    PLANNED

    IMPLEMENTED

    TESTED

    RELEASED

    DROPPED

    POSTPONED

    up

    up

    up

    up

    up

    up

    FAILED

    up

    up

    up

    down

    init

    up

    down

    down

    down

    down

    down

    down

    down

    down

    down

  • 7/30/2019 ReqT Intro

    20/41

    Status(value: Level)

    SPECIFIED

    ELICITED

    VALIDATED

    PLANNED

    IMPLEMENTED

    TESTED

    RELEASED

    DROPPED

    POSTPONED

    up

    up

    up

    up

    up

    up

    FAILED

    up

    up

    up

    down

    init

    up

    down

    down

    down

    down

    down

    down

    down

    down

    down

    scala> val s = Status.init

    s: reqT.Status =Status(ELICITED)

    scala> s.upres1: reqT.Status =Status(SPECIFIED)

    scala> s.downres2: reqT.Status =Status(DROPPED)

  • 7/30/2019 ReqT Intro

    21/41

    Creating and updating Status in reqTscala> var m = Model(Feature("x") has Status.init, Feature("y") has Status.init)

    m: reqT.Model =Model(

    Feature("x") has Status(ELICITED),

    Feature("y") has Status(ELICITED)

    )

    scala> m.up

    res8: reqT.Model =

    Model(

    Feature("x") has Status(SPECIFIED),

    Feature("y") has Status(SPECIFIED)

    )

    scala> m = (m / Feature("x")).up ++ (m \ Feature("x"))

    m: reqT.Model = Model(

    Feature("x") has Status(SPECIFIED),

    Feature("y") has Status(ELICITED)

    )

    scala> m = m up Feature("x") //equivalent shorter way to do previous

    restrict operator

    aggregate operator

    exclude operator

  • 7/30/2019 ReqT Intro

    22/41

    Priorities

    Any entity can have an integer priority attribute:Model(

    Feature("x") has Prio(10),

    UserStory("u") has Prio(20),

    Stakeholder("s") has Prio(5)

    )

    Priotities can also be expressed as relations between entities:

    Model(

    Stakeholder("s") assigns(Prio(5)) to Feature("x"),

    Stakeholder("s") assigns(Prio(1)) to Feature("y"),

    Stakeholder("s") assigns(Prio(9)) to Feature("z")

    )

  • 7/30/2019 ReqT Intro

    23/41

    reqT Data requirement example

    Model(

    Class("Guest") has (

    Gist("Pays the bill."),

    Spec("The guest is the person or company who has to pay the bill. A guest hasone or more stay records. 'Customer' is a synonym for guest but in the databasewe only use 'guest'. The persons staying in the rooms are also called guests but

    are not guests in database terms."),Example("(1) A guest who stays one night. (2) A company with employeesstaying now and then each of them with his own stay record where his name isrecorded. (3) A guest with several rooms within the same stay.")

    ),

    Member("name") has Spec("Text, 50 chars. The name stated by the guest. Forcompanies the official name since the bill is sent there. Longer names exist but

    better truncate at registration time than at print out time."),Member("passport") has Spec("Text 12 chars. Recorded for guests who are

    obviously foreigners. Used for police reports in case the guest does not pay."),

    Class("Guest") owns (Member("name"), Member("passport"))

    )

    [Example modified from Lauesen: "Software Requirements Styles and Techniques"]

  • 7/30/2019 ReqT Intro

    24/41

    reqT Data Model example

    Model(

    Class("Guest") assigns(Label("1:m")) to Class("Stay"),

    Class("Stay") assigns(Label("1:m")) to Class("RoomState"),

    Class("Room") assigns(Label("1:m")) to Class("RoomState"),

    Function("Room database") has Image("ER-diagram.png"),

    Function("Room state") has Image("room-state-diagram.png"))

    [Example modified from Lauesen: "Software Requirements Styles and Techniques"]

  • 7/30/2019 ReqT Intro

    25/41

    reqT Image example

    Model(

    Function("guest data") has (

    Spec("The product shall store guest data accordingto virtual window 'create guest data'."),

    Image("create-guest-data.png"))

    )

    [Example modified from Lauesen: "Software Requirements Styles and Techniques"]

  • 7/30/2019 ReqT Intro

    26/41

    reqT Context diagram exampleModel(

    Product("Hotel system") owns (

    Interface("ReceptionUI"), Interface("GuestUI"),Interface("TelephonyAPI"), Interface("AccountingAPI")

    ),

    Product("Hotel system") has Image("context-diagram.png"),

    Interface("ReceptionUI") has (

    Input("booking, check-out"), Output("service note"),

    Image("recetionUI-screen.png")

    ),

    Interface("GuestUI") has (

    Output("confirmation, invoice"),

    Image("guestUI-screen.png")),

    Actor("Receptionist") requires Interface("ReceptionUI"),Actor("Guest") requires Interface("GuestUI"),

    Actor("Receptionist") requires Interface("ReceptionUI"),

    Actor("Telephony System") requires Interface("TelephonyAPI"),

    Actor("Accounting System") requires Interface("AccountingAPI")

    )

    [Example modified from Lauesen: "Software Requirements Styles and Techniques"]

  • 7/30/2019 ReqT Intro

    27/41

    reqT Task description example

    Model(

    Task("reception work") owns (Task("check in"), Task("booking")),

    Task("check in") has (

    Why("Give guest a room. Mark it as occupied. Start account."),

    Trigger("A guest arrives"),

    Frequency("Average 0.5 checkins/room/day"),Critical("Group tour with 50 guests.")

    ),

    Task("check in") owns (

    Task("find room"), Task("record guest"), Task("deliver key")),

    Task("record guest") has Spec(

    "variants: a) Guest has booked in advance, b) No suitable room"

    )

    )

    [Example modified from Lauesen: "Software Requirements Styles and Techniques"]

  • 7/30/2019 ReqT Intro

    28/41

    reqT Quality requirement examples

    Model(

    Quality("capacity database") has Spec("#guests < 10,000 growing 20% peryear, #rooms < 1,000"),

    Quality("accuracy calendar") has Spec("Bookings shall be possible at leasttwo years ahead."),

    Quality("performance forecast") has Spec("Product shall compute a roomoccupation forecast within ___ minutes. (Customer expects one minute.)"),

    Quality("usability task time") has Spec("Novice users shall perform tasks Qand R in 15 minutes. Experienced users tasks Q, R, S in 2 minutes."),

    Quality("usability task time") requires (Task("Q"), Task("R"), Task("S"))

    Quality("performance peak load") has Spec("Product shall be able to process100 payment transactions per second in peak load.")

    )

    [Examples modified from Lauesen: "Software Requirements Styles and Techniques"]

    T QUPER l

  • 7/30/2019 ReqT Intro

    29/41

    var m = Model(

    UserStory("playMusic") has Spec("As a user I want to play music."),

    UserStory("playMusic") requires Quality("timeToMusic"),

    Quality("performance") owns (Quality("timeToMusic"), Quality("timeToVideo")),Quality("timeToMusic.metric") has Spec("Measured in seconds using tests XYZ."),

    Quality("timeToMusic.ref.X") has (Spec("4.0 s"), Comment("Competitor product X.")),

    Quality("timeToMusic.ref.Y") has (Spec("2.0 s"), Comment("Competitor product Y.")),

    Quality("timeToMusic.ref.Z") has (Spec("3.0 s"), Comment("Our own released product Z.")),

    Quality("timeToMusic.utility") has Spec("5.0 s"),

    Quality("timeToMusic.differentiation") has Spec("1.5 s"),

    Quality("timeToMusic.saturation") has Spec("0.2 s"),

    Quality("timeToMusic.barrier.1") has Spec("2.0 s requires Effort(Range(4,5),Weeks)"),

    Quality("timeToMusic.barrier.2") has Spec("1.0 s requires Effort(Range(24,48),Weeks)"),

    Quality("timeToMusic.target.min") has (Spec("2.0 s"),

    Comment("Probably possible with existing architecture.")),

    Quality("timeToMusic.target.max") has (Spec("1.0 s"),

    Comment("Probably needs new architecture.")),

    Quality("timeToMusic") has Image("QUPER-timeToMusic.jpg")

    )

    reqT QUPER example

    [Example modified from "Setting quality targets for coming releases with QUPER: an industrial case study",

    R. Berntsson Svensson, Y. Sprockel, B. Regnell, S. Brinkkemper, Requirements Engineering, DOI: 10.1007/s00766-011-0125-0]

    "Actual" requirements given

    meaning by this model

  • 7/30/2019 ReqT Intro

    30/41

    Sources & destinations in reqT graph structures

    Model(

    Feature("f1") requires (Feature("f2"), Feature("f3")),

    Stakeholder("s1") assigns(Prio(1)) to Feature("f2")

    )

    Feature

    ("f1")

    Feature

    ("f2")

    requires

    Stakeholder

    ("s1")

    assigns(Prio(1))sources

    destinations

    Feature("f3")

    requires

  • 7/30/2019 ReqT Intro

    31/41

    Add, Restrict, Exclude, Split, Aggregate

    var m = Model() Create an empty model.

    m += Feature("hello") has Spec("print da stuff") Add an entity with one attribute.

    m += Feature("f1") has (Gist("g1"), Spec("s1")) Add an entity with several attributes.m += Feature("f1") has Gist("g2") Adding existing attributes overwrites old.

    m += Product("p1") owns (Feature("f1"), Feature("hello")) Add a relation. "Owns" is a special relationthat enforces hierarchical decomposition.

    var m2 = m Feature("f1") Remove an entity also in relations.

    m / Feature("f1") A restriction returns a new Model that is a

    submodel including only some elements.

    m / Feature Entity types can be used to restrict thesubmodel to any element of that type.

    m / Spec Attributes can also be used in restrictions.

    m / Context Restriction on an abstract type.

    m / Feature / Gist Restrictions can be stacked.

    m /+ Feature("f1") An extendedrestriction returns a submodelincluding also related nodes.

    m \ Feature An exclusion gives everything but this.

    val (m1, m2) = m | Feature Apartition gives a pair with a model split:(m / Feature, m \ Feature)

    m ++ m2Aggregate two models.

    m + Gist("same same") Add the same attribute to all entities.

  • 7/30/2019 ReqT Intro

    32/41

    reqT script for adding owns-relations

    var m = Model( /* QUPER example from previous slide */)

    scala> val s = "timeToMusic"

    s: java.lang.String = timeToMusic

    scala> val ttm = Quality(s)

    ttm: reqT.Quality = Quality(timeToMusic)

    scala> val ttms = m / (s + ".") sourcesttms: Set[reqT.Entity] = Set(Quality(timeToMusic/target/min),Quality(timeToMusic/metric), Quality(timeToMusic/barrier/2), Quality(timeToMusic/ref/X),Quality(timeToMusic/ref/Y), Quality(timeToMusic/ref/Z),Quality(timeToMusic/differentiation), Quality(timeToMusic/utility),

    Quality(timeToMusic/saturation), Quality(timeToMusic/target/max),Quality(timeToMusic/barrier/1))

    scala> m += ttm.owns(ttms.toArray:_*)

  • 7/30/2019 ReqT Intro

    33/41

    reqT.org types Element

    Concept Structure

    Node

    Entity(id: String)

    Context

    Product

    Release

    Stakeholder

    Requirement

    Feature

    UserStory

    Goal

    Attribute[T](value: T)

    Edge

    AttributeEdge

    Relation

    has

    Key(Entity, Edge)

    NodeSet(Node, Node, ...)

    owns

    excludes

    assigns(Attribute)

    Actor

    Model

    scala.collection.immutable.Map[Key, NodeSet]

    UseCase

    TaskScenario

    VividScenario

    Function

    Data

    Quality

    Interface

    Spec(String)

    Gist(String)

    Status(Level)

    Why(String)

    Example(String)

    Input(String)

    Design

    precedesOutput(String)

    Trigger(String)

    Precond(String)

    Frequency(String)

    Critical(String)

    Problem(String)Prio(Int)

    Label(String)

    Image(String)

    Class

    Member

    inherits

    requires

    helps

    hurts

    Abstract

    Type

    subtype

    Comment(String)

    Deprecated(String)

    deprecates

  • 7/30/2019 ReqT Intro

    34/41

    Very short intro to Scala syntax

    Similar to Java, but types are placed afteridentifiers with colon but not

    needed if they can be inferred by the compiler

    val s1: String = "hello"

    val s2 = "hello" // type String is inferred and not needed

    Functions are objects and can be passed as values

    def f(x: Int) = 2 * x // function definition

    scala> List(1,2,3).map(f) // passed as argument to map function

    res0: List[Int] = List(2, 4, 6)

    scala> List(1,2,3).map(x => 2 * x) // unnamed function literal

    res1: List[Int] = List(2, 4, 6)

    scala> List(1,2,3).map(2 * _) // short form: placeholder parameter

    res2: List[Int] = List(2, 4, 6)

    Syntax is flexible: you can skip dots and parentheses in some cases"abc" + "xyz" // string concatenation, short for:

    scala> "abc".+("xyz") // object.method(singleParameter)

    res3: java.lang.String = abcxyz

    Scala tutorial for Java programmers: http://docs.scala-lang.org/tutorials/

    http://docs.scala-lang.org/tutorials/http://docs.scala-lang.org/tutorials/
  • 7/30/2019 ReqT Intro

    35/41

    What can you do with a Scala Map?

    You can associate keys with values in Maps to get an associate

    array for fast element retrieval:

    scala> var m = Map("dog" -> 84, "cat" -> 42, "bird" -> 21)

    m: scala.collection.immutable.Map[java.lang.String,Int] =Map(dog -> 84, cat -> 42, bird -> 21)

    scala> m("cat")

    res10: Int = 42

    Maps are efficient and have many useful operations:

    http://docs.scala-lang.org/overviews/collections/maps.html

    http://docs.scala-lang.org/overviews/collections/maps.htmlhttp://docs.scala-lang.org/overviews/collections/maps.htmlhttp://docs.scala-lang.org/overviews/collections/maps.htmlhttp://docs.scala-lang.org/overviews/collections/maps.htmlhttp://docs.scala-lang.org/overviews/collections/maps.html
  • 7/30/2019 ReqT Intro

    36/41

    Boosting your requirements models

    with the power of Scala collections

    A reqT Model is a map of Key(Entity, Edge) -> NodeSet

    class Model(val mappings: scala.collection.immutable.SortedMap(Key, NodeSet)

    )extends scala.collection.immutable.Map(Key, NodeSet)

    scala> val kns = Feature("f") has (Gist("g"), Spec("s"), Prio(1))kns: (reqT.Key, reqT.NodeSet) =(Key(Feature(f),has()),NodeSet(Gist(g), Spec(s), Prio(1)))

    scala> Model(kns)res42: reqT.Model =Model(Feature("f") has (

    Gist("g"),Spec("s"),Prio(1)

    ))

  • 7/30/2019 ReqT Intro

    37/41

    Example use of powerful Scala scripting:

    Collecting and looping with guards

    // extract all entities that have priority < 5

    val highPrio: Model = m collect {

    case (Key(entity,edge), nodes)

    if nodes exists {

    case Prio(p) => p < 5

    case _ => false} => (Key(entity,edge), nodes)

    }

    // do the same with a for-comprehension

    val highPrio: Model = for (

    (Key(entity,edge), nodes) p < 5

    case _ => false

    }

    ) yield (Key(entity,edge), nodes)

    E t ti tt ib t f d l

  • 7/30/2019 ReqT Intro

    38/41

    Extracting attributes from models

    var m = Model(Feature("f1") has (Gist("g1"), Spec("s1")),Feature("f2") has Gist("g2")

    )

    val s = m ! Gist s: Option[String] =Some(g1)

    Extract some Gist: Get the string

    of the first Gist in m.

    val s2 = m / Feature("f2") ! Gist s2: Option[String] =Some(g2)

    Get the string of the Gist of f2

    s2 match {case Some(str) => println(str)case None =>

    }

    g2 If s is Some[String] then print it,else if s is None then do nothing.

    s2.foreach(println) g2 Same effect as above

    val s3 = m / Feature("f2") ! Spec s3: Option[String] =None

    As f2 does not have a Spec, s3

    gets the value None instead of

    Some[String]val s4 = m / Feature("f1") !! Gist s4: String = g1 Extract value or default:

    Get the value if it exists.

    val s5 = m / Feature("f2") !! Spec s5: String =UNDEFINED SPECIFICATION

    Extract value or default:

    If the value does not exist, a

    default value is given.

    E t ti t f t f d l

  • 7/30/2019 ReqT Intro

    39/41

    Extracting sets of concepts from models

    var m = Model(Feature("f1") has Spec("A"),Feature("f2") has Spec("B"),

    Feature("f1") owns (Feature("f2"), Feature("f3")),Product("p1") requires (Feature("f1"), Feature("f2")

    ),Feature("f4") has Gist("C"))

    Models can be constructed by applying sequences of entities linked to one or

    many nodes via either hasor some relation, such as owns, requires,

    excludes, etc. (See further the reqT type structure.)

    The nodes (entities, attributes) and relations can be extracted using various

    operations on models explained below.

    m.sources f1,f2,p1,f4 Set of all entities that are sources of links in model m.

    m.destinations f1,f2,f3 Set of all entities that are destinations of relations in model m.

    m.entities f1,f2,f3,p1,f4 Set of all entities. Same as: m.sources ++ m.destinations

    m.undefined f3 Set of all entities that are destinations and not sources. Same as:for (e

  • 7/30/2019 ReqT Intro

    40/41

    Some predicates defined in class Model

    def isSource(e: Entity): Boolean = sources.contains(e)

    def isDestination(e: Entity): Boolean = destinations.contains(e)

    def isUndefined(e: Entity): Boolean = undefined.contains(e)

    def isDefined(e: Entity): Boolean = !isUndefined(e)

    def hasAttribute[T](a: Attribute[T]):Boolean = attributes.contains(a)

    def isRoot(e: Entity): Boolean = roots.contains(e)

    def isParent(e: Entity): Boolean = parents.contains(e)

    def isChild(e: Entity): Boolean = children.contains(e)

    I t d t d l t t i d fil

  • 7/30/2019 ReqT Intro

    41/41

    Import and export models to strings and files

    var m = Model(Feature("f") has Spec("s")) Create a new model.

    m.toTable Gives a string in tab-separated table format.

    m.toTable(";", false) Gives a table separated with ; and with no heading row.m.toScala Gives a string with the Scala code that generates the model.

    m.toTable.save("mymodel.txt") Save the table string to a file.

    m.toScala.save("mymodel.scala") Save the Scala code that generates the model.

    m.toScala.save("C:/Users/xx/mymodel.scala") Specify an absolute path where to save the file.

    val s = Model.fromTable("mymodel.txt")s.save("mymodel.scala")

    Load a model into a String from a tab-separated text file.

    Save the loaded string as a model that can be interpreted.

    :load mymodel.scala Interpret a scala file in the Scala REPL. Use last resX val.

    interpret("var m = " + s) In Kojo: interpret a String s containing a model.

    m.toHtml Generate HTML code using the default document template

    m.toHtml.save("mymodel.html") Save it to a file.

    val myDocTempl = DocumentTemplate("Title",Text("Intro para1", "Intro para2"),Chapter("Chap 1", Text("the model"),m => m

    ))

    Create a minimal document template.

    m.toHtml(myDocTempl) Use myDocTempl as document template for HTML