Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/11/08 14:33:04 (16 years ago)
Author:
gkronber
Message:

improved SelectProperties operator to query only one specific predicate. #200 (Simple indexer for results and matching search-frontend for solution-quality)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Operators/SelectProperties.cs

    r547 r549  
    4545      AddVariableInfo(new VariableInfo("CedmaServerUri", "Uri of the CEDMA server", typeof(StringData), VariableKind.In));
    4646      AddVariableInfo(new VariableInfo("SubjectGuid", "", typeof(StringData), VariableKind.In));
     47      AddVariableInfo(new VariableInfo("Predicate", "", typeof(StringData), VariableKind.In));
     48      AddVariableInfo(new VariableInfo("Property", "", typeof(IItem), VariableKind.New));
    4749    }
    4850
     
    5052      string serverUrl = GetVariableValue<StringData>("CedmaServerUri", scope, true).Data;
    5153      StringData subjectGuid = GetVariableValue<StringData>("SubjectGuid", scope, true);
     54      StringData predicate = GetVariableValue<StringData>("Predicate", scope, true);
    5255
    5356      NetTcpBinding binding = new NetTcpBinding();
     
    6063        Statement template = new Statement(
    6164          new Entity(cedmaNamespace+subjectGuid.Data),
    62           new Entity(null),
     65          new Entity(cedmaNamespace+predicate.Data),
    6366          new Entity(null));
    6467        IList<Statement> result = store.Select(template);
    6568
    66         foreach(Statement s in result) {
     69        if(result.Count == 1) {
     70          Statement s = result[0];
     71          Variable var = new Variable();
     72          var.Name = scope.TranslateName("Property");
     73          scope.AddVariable(var);
    6774          if(s.Property is Literal) {
    68             scope.AddVariable(new Variable(s.Predicate.Uri.Replace(cedmaNamespace,""), TranslateLiteral((Literal)s.Property)));
     75            var.Value = TranslateLiteral((Literal)s.Property);
    6976          } else if(s.Property is SerializedLiteral) {
    70             scope.AddVariable(new Variable(s.Predicate.Uri.Replace(cedmaNamespace, ""), TranslateLiteral((SerializedLiteral)s.Property)));
     77            var.Value = TranslateLiteral((SerializedLiteral)s.Property);
    7178          } else {
    72             scope.AddVariable(new Variable(s.Predicate.Uri, new StringData(((Entity)s.Property).Uri.Replace(cedmaNamespace, ""))));
     79            var.Value = new StringData(((Entity)s.Property).Uri.Replace(cedmaNamespace, ""));
     80          }
     81        } else {
     82          ItemList<IItem> resultValues = new ItemList<IItem>();
     83          scope.AddVariable(new Variable(scope.TranslateName("Property"), resultValues));
     84          foreach(Statement s in result) {
     85            if(s.Property is Literal) {
     86              resultValues.Add(TranslateLiteral((Literal)s.Property));
     87            } else if(s.Property is SerializedLiteral) {
     88              resultValues.Add(TranslateLiteral((SerializedLiteral)s.Property));
     89            } else {
     90              resultValues.Add(new StringData(((Entity)s.Property).Uri.Replace(cedmaNamespace, "")));
     91            }
    7392          }
    7493        }
Note: See TracChangeset for help on using the changeset viewer.