Exemplo n.º 1
0
def loadFeature(feat, claferFeat, indent, parentoptional):
  print ' ' * indent + claferFeat,
  if claferFeat in cache:
    print colored('~ DUPLICATE', 'yellow')
    return ['', []]
  cache.append(claferFeat)
  triples = tripleLoader.load(feat)
  isLeaf = all(map(lambda t: t['predicate'] != basePropURL + 'isA' or t['direction'] != 'IN', triples))
  res = '\n' + ' ' * indent
  optional = any(map(lambda t: t['predicate'] == basePropURL + 'isA' and t['direction'] == 'OUT' and t['node'] ==  'Optional feature', triples))
  mandatory = any(map(lambda t: t['predicate'] == basePropURL + 'isA' and t['direction'] == 'OUT' and t['node'] ==  'Mandatory feature', triples))
  alternative = any(map(lambda t: t['predicate'] == basePropURL + 'isA' and t['direction'] == 'OUT' and t['node'] ==  'Alternative feature', triples))
  or_ = any(map(lambda t: t['predicate'] == basePropURL + 'isA' and t['direction'] == 'OUT' and t['node'] ==  'Or feature', triples))
  impliedFeatsTriples = filter(lambda t: t['predicate'] == basePropURL + 'implies' and t['direction'] == 'OUT' ,triples)
  impliedClaferFeats = map(lambda t:  tripleLoader.urlTourlName(tripleLoader.urlNameToClafer(t['node']),'Feature:'), impliedFeatsTriples)
  print colored('=> (' + ', '.join(impliedClaferFeats) + ')', 'cyan'),
  for implied in impliedClaferFeats:
    if claferFeat in implications:
      implications[claferFeat].append(implied)
    else:
      implications[claferFeat] = [implied]
  if isLeaf:
    leafs.append(claferFeat)
    print colored('~', 'green'),
    res += re.sub("Feature:", "", claferFeat)
    if optional or parentoptional:
      print colored( 'OPTIONAL', 'green'),
      res += ' ?'
    print colored('LEAF', 'green')
    return [res, re.sub("Feature:", "", claferFeat)]
  else:
    if optional:
      print colored('~ OPTIONAL', 'blue'),
      if alternative:
        print colored('ALTERNATIVE (MUX)', 'blue'),
        res += 'mux ' + re.sub("Feature:", "", claferFeat)
      if or_:
        print colored('OR (ANY)', 'blue'),
        res += re.sub("Feature:", "", claferFeat)
    if mandatory:
      print colored('~ MANDATORY', 'blue'),
      if alternative:
        print colored('ALTERNATIVE (XOR)', 'blue'),
        res += 'xor ' + re.sub("Feature:", "", claferFeat)
      if or_:
        print colored('OR (OR)', 'blue'),
        res += 'or ' + re.sub("Feature:", "", claferFeat)
    print colored('NODE', 'blue')
    subFeatTriples = filter(lambda t: t['predicate'] == basePropURL + 'isA' and t['direction'] == 'IN', triples)
    subStr = ""
    subOs = {}
    for ft in subFeatTriples:
      feat = tripleLoader.urlTourlName(ft['node'], 'Feature:')
      claferFeat = tripleLoader.urlNameToClafer(feat)
      [subFeat, o] = loadFeature(feat, claferFeat, indent + 2, optional and or_)
      if len(o) > 0:
        subOs[re.sub("Feature:", "", claferFeat)] = o
      subStr += subFeat
    return [res + subStr, subOs]
Exemplo n.º 2
0
def contribToClafer(contrib, claferTree, allFeatures):
  triples = tripleLoader.load( "Contribution-3A" + contrib)
  implementedTriples = filter(lambda t : t['predicate'] == "http://101companies.org/property/implements", triples)
  implemented = map(lambda t : tripleLoader.urlToClafer(t['node'], 'Feature-3A'), implementedTriples)
  print implemented
  notImplemented = set(allFeatures) - set(implemented)
  print printIndent(claferTree, 0, implemented)
  if not implemented:
    raise Exception("No implemented features specified.")
  return contrib.title() + " : FeatureSpec\n [ \n" + printIndent(claferTree, 0, implemented) + '\n]'
Exemplo n.º 3
0
def loadRequirement(req, claferReq, indent):
  print claferReq + 's'
  triples = tripleLoader.load(req)
  reqTriples = filter(lambda t: t['node'].find('Feature:') != -1 and t['predicate'] == basePropURL + 'isA' and t['direction'] == 'IN', triples)
  features = ''
  featOs = {}
  for rt in reqTriples:
    feat = tripleLoader.urlTourlName(rt['node'], 'Feature:')
    claferFeat = tripleLoader.urlNameToClafer(feat)
    [f, o] = loadFeature(feat, claferFeat, indent + 2, False)
    features += f
    if len(o) > 0:
      featOs[re.sub("Feature:", "", claferFeat)] = o
  return ('\n' + ' ' * indent + claferReq + features + '\n', featOs)
Exemplo n.º 4
0
def contribToClafer(contrib, claferTree, allFeatures):
    triples = tripleLoader.load("Contribution-3A" + contrib)
    implementedTriples = filter(
        lambda t: t['predicate'] ==
        "http://101companies.org/property/implements", triples)
    implemented = map(
        lambda t: tripleLoader.urlToClafer(t['node'], 'Feature-3A'),
        implementedTriples)
    print implemented
    notImplemented = set(allFeatures) - set(implemented)
    print printIndent(claferTree, 0, implemented)
    if not implemented:
        raise Exception("No implemented features specified.")
    return contrib.title() + " : FeatureSpec\n [ \n" + printIndent(
        claferTree, 0, implemented) + '\n]'
Exemplo n.º 5
0
def loadRequirement(req, claferReq, indent):
    print claferReq + 's'
    triples = tripleLoader.load(req)
    reqTriples = filter(
        lambda t: t['node'].find('Feature:') != -1 and t['predicate'] ==
        basePropURL + 'isA' and t['direction'] == 'IN', triples)
    features = ''
    featOs = {}
    for rt in reqTriples:
        feat = tripleLoader.urlTourlName(rt['node'], 'Feature:')
        claferFeat = tripleLoader.urlNameToClafer(feat)
        [f, o] = loadFeature(feat, claferFeat, indent + 2, False)
        features += f
        if len(o) > 0:
            featOs[re.sub("Feature:", "", claferFeat)] = o
    return ('\n' + ' ' * indent + claferReq + features + '\n', featOs)
Exemplo n.º 6
0
  featOs = {}
  for rt in reqTriples:
    feat = tripleLoader.urlTourlName(rt['node'], 'Feature:')
    claferFeat = tripleLoader.urlNameToClafer(feat)
    [f, o] = loadFeature(feat, claferFeat, indent + 2, False)
    features += f
    if len(o) > 0:
      featOs[re.sub("Feature:", "", claferFeat)] = o
  return ('\n' + ' ' * indent + claferReq + features + '\n', featOs)

#main
parser = argparse.ArgumentParser()
parser.add_argument('-cf', required=True, help='file to write clafer model to')
parser.add_argument('-flatf', required=True, help='file to write flat list of clafer features to')
args = parser.parse_args()
reqsTriples = filter(lambda t: t['predicate'] == basePropURL + 'isA',  tripleLoader.load('Requirement'))
res = 'abstract FeatureSpec'
res += '\n'
reqsObject = {}
for rt in reqsTriples:
  req = tripleLoader.urlTourlName(rt['node'], '')
  claferReq = tripleLoader.urlNameToClafer(req)
  [r, o] = loadRequirement(req, claferReq, 2)
  res += r
  if len(o) > 0:
    reqsObject[claferReq] = o
res += '\n  ' + '\n  '.join(map(lambda t: '[' + re.sub("Feature:", "", t[0]) + ' => ' + re.sub("Feature:", "", t[1]) + ']', implications))
with open(args.cf, 'w+') as f:
  f.write(res)
with open(args.flatf, 'w+') as f:
  f.write(json.dumps(leafs))
Exemplo n.º 7
0
import json
import urllib2
import checker
import tripleLoader

def writeReport(report, pathBase):
  with open(pathBase + '.json', 'w+') as reportf:
    json.dump(report, reportf)
  with open(pathBase + '.jsonp', 'w+') as reportpf:
    reportpf.write('callback(' + json.dumps(report) + ')')

contribNames = sorted(json.loads(file(sys.argv[3]).read())['dirs'])
allSupportedClaferFeatures = sorted(json.loads(file(sys.argv[1]).read()))
summary = {}
# load features and convert to clafer names
rawFeatureTriples = tripleLoader.load("Namespace-3AFeature")
instanceOfURL = 'http://101companies.org/property/instanceOf'
namespaceURL = 'http://101companies.org/resource/Namespace-3ANamespace'
featureTriples = filter(lambda t : t['predicate'] == instanceOfURL and (t['node'] != namespaceURL),  rawFeatureTriples)
allClaferFeatures = map(lambda t : tripleLoader.urlToClafer(t['node'], 'Feature-3A'), featureTriples)
claferTreeRaw = urllib2.urlopen('http://data.101companies.org/dumps/features.clf.json')
claferTree = json.load(claferTreeRaw)['structure']
# check all contributions
for contribName in contribNames:
  print 'Checking ' + contribName + '...',
  report = checker.check(contribName, claferTree, allSupportedClaferFeatures, sys.argv[2])
  print 'done.'
  writeReport(report, sys.argv[4] + sys.argv[5] + contribName)
  summary[contribName] = report
writeReport(summary, sys.argv[4] + 'featureModelReport')
Exemplo n.º 8
0
def loadFeature(feat, claferFeat, indent, parentoptional):
    print ' ' * indent + claferFeat,
    if claferFeat in cache:
        print colored('~ DUPLICATE', 'yellow')
        return ['', []]
    cache.append(claferFeat)
    triples = tripleLoader.load(feat)
    isLeaf = all(
        map(
            lambda t: t['predicate'] != basePropURL + 'isA' or t['direction']
            != 'IN', triples))
    res = '\n' + ' ' * indent
    optional = any(
        map(
            lambda t: t['predicate'] == basePropURL + 'isA' and t['direction']
            == 'OUT' and t['node'] == 'Optional feature', triples))
    mandatory = any(
        map(
            lambda t: t['predicate'] == basePropURL + 'isA' and t['direction']
            == 'OUT' and t['node'] == 'Mandatory feature', triples))
    alternative = any(
        map(
            lambda t: t['predicate'] == basePropURL + 'isA' and t['direction']
            == 'OUT' and t['node'] == 'Alternative feature', triples))
    or_ = any(
        map(
            lambda t: t['predicate'] == basePropURL + 'isA' and t['direction']
            == 'OUT' and t['node'] == 'Or feature', triples))
    impliedFeatsTriples = filter(
        lambda t: t['predicate'] == basePropURL + 'implies' and t['direction']
        == 'OUT', triples)
    impliedClaferFeats = map(
        lambda t: tripleLoader.urlTourlName(
            tripleLoader.urlNameToClafer(t['node']), 'Feature:'),
        impliedFeatsTriples)
    print colored('=> (' + ', '.join(impliedClaferFeats) + ')', 'cyan'),
    for implied in impliedClaferFeats:
        if claferFeat in implications:
            implications[claferFeat].append(implied)
        else:
            implications[claferFeat] = [implied]
    if isLeaf:
        leafs.append(claferFeat)
        print colored('~', 'green'),
        res += re.sub("Feature:", "", claferFeat)
        if optional or parentoptional:
            print colored('OPTIONAL', 'green'),
            res += ' ?'
        print colored('LEAF', 'green')
        return [res, re.sub("Feature:", "", claferFeat)]
    else:
        if optional:
            print colored('~ OPTIONAL', 'blue'),
            if alternative:
                print colored('ALTERNATIVE (MUX)', 'blue'),
                res += 'mux ' + re.sub("Feature:", "", claferFeat)
            if or_:
                print colored('OR (ANY)', 'blue'),
                res += re.sub("Feature:", "", claferFeat)
        if mandatory:
            print colored('~ MANDATORY', 'blue'),
            if alternative:
                print colored('ALTERNATIVE (XOR)', 'blue'),
                res += 'xor ' + re.sub("Feature:", "", claferFeat)
            if or_:
                print colored('OR (OR)', 'blue'),
                res += 'or ' + re.sub("Feature:", "", claferFeat)
        print colored('NODE', 'blue')
        subFeatTriples = filter(
            lambda t: t['predicate'] == basePropURL + 'isA' and t['direction']
            == 'IN', triples)
        subStr = ""
        subOs = {}
        for ft in subFeatTriples:
            feat = tripleLoader.urlTourlName(ft['node'], 'Feature:')
            claferFeat = tripleLoader.urlNameToClafer(feat)
            [subFeat, o] = loadFeature(feat, claferFeat, indent + 2, optional
                                       and or_)
            if len(o) > 0:
                subOs[re.sub("Feature:", "", claferFeat)] = o
            subStr += subFeat
        return [res + subStr, subOs]
Exemplo n.º 9
0
        [f, o] = loadFeature(feat, claferFeat, indent + 2, False)
        features += f
        if len(o) > 0:
            featOs[re.sub("Feature:", "", claferFeat)] = o
    return ('\n' + ' ' * indent + claferReq + features + '\n', featOs)


#main
parser = argparse.ArgumentParser()
parser.add_argument('-cf', required=True, help='file to write clafer model to')
parser.add_argument('-flatf',
                    required=True,
                    help='file to write flat list of clafer features to')
args = parser.parse_args()
reqsTriples = filter(lambda t: t['predicate'] == basePropURL + 'isA',
                     tripleLoader.load('Requirement'))
res = 'abstract FeatureSpec'
res += '\n'
reqsObject = {}
for rt in reqsTriples:
    req = tripleLoader.urlTourlName(rt['node'], '')
    claferReq = tripleLoader.urlNameToClafer(req)
    [r, o] = loadRequirement(req, claferReq, 2)
    res += r
    if len(o) > 0:
        reqsObject[claferReq] = o
res += '\n  ' + '\n  '.join(
    map(
        lambda t: '[' + re.sub("Feature:", "", t[0]) + ' => ' + re.sub(
            "Feature:", "", t[1]) + ']', implications))
with open(args.cf, 'w+') as f:
Exemplo n.º 10
0
import checker
import tripleLoader


def writeReport(report, pathBase):
    with open(pathBase + '.json', 'w+') as reportf:
        json.dump(report, reportf)
    with open(pathBase + '.jsonp', 'w+') as reportpf:
        reportpf.write('callback(' + json.dumps(report) + ')')


contribNames = sorted(json.loads(file(sys.argv[3]).read())['dirs'])
allSupportedClaferFeatures = sorted(json.loads(file(sys.argv[1]).read()))
summary = {}
# load features and convert to clafer names
rawFeatureTriples = tripleLoader.load("Namespace-3AFeature")
instanceOfURL = 'http://101companies.org/property/instanceOf'
namespaceURL = 'http://101companies.org/resource/Namespace-3ANamespace'
featureTriples = filter(
    lambda t: t['predicate'] == instanceOfURL and (t['node'] != namespaceURL),
    rawFeatureTriples)
allClaferFeatures = map(
    lambda t: tripleLoader.urlToClafer(t['node'], 'Feature-3A'),
    featureTriples)
claferTreeRaw = urllib2.urlopen(
    'http://data.101companies.org/dumps/features.clf.json')
claferTree = json.load(claferTreeRaw)['structure']
# check all contributions
for contribName in contribNames:
    print 'Checking ' + contribName + '...',
    report = checker.check(contribName, claferTree, allSupportedClaferFeatures,