Package edu.mit.simile.fresnel.selection

Examples of edu.mit.simile.fresnel.selection.ISelector


     */
    protected static void parseDomain(Format out, Repository in, Resource selected, Configuration conf) throws RepositoryException {
      RepositoryConnection conn = in.getConnection();
        RepositoryResult<Statement> domainsI = conn.getStatements(selected, FresnelCore.propertyFormatDomain, (Value) null, false);
      while (domainsI.hasNext()) {
        ISelector domain = null;
        Value domainNode = domainsI.next().getObject();
        if (domainNode instanceof Resource) {
          if (((Resource) domainNode).equals(AllPropertiesSet.getSchemaResource())) {
            domain = new AllPropertiesSelector();
          } else {
View Full Code Here


   */
  protected static void parseDomain(Format out, Repository in, Resource selected, Configuration conf) throws RepositoryException {
    RepositoryConnection conn = in.getConnection();
        RepositoryResult<Statement> domainsI = conn.getStatements(selected, FresnelCore.instanceFormatDomain, (Value) null, false);
    while (domainsI.hasNext()) {
      ISelector domain = null;
      Value domainNode = domainsI.next().getObject();
      if (domainNode instanceof Resource) {
        // This is an instance selector
        domain = new InstanceSelector((URI) domainNode);
      } else if (domainNode instanceof Literal) {
View Full Code Here

   */
  protected static void parseDomain(Format out, Repository in, Resource selected, Configuration conf) throws RepositoryException {
    RepositoryConnection conn = in.getConnection();
        RepositoryResult<Statement> domainsI = conn.getStatements(selected, FresnelCore.classFormatDomain, (Value) null, false);
    while (domainsI.hasNext()) {
      ISelector domain = null;
      Value domainNode = domainsI.next().getObject();
      if (domainNode instanceof Resource) {
        // This is a type selector
        domain = new TypeSelector((URI) domainNode);
      } else if (domainNode instanceof Literal) {
View Full Code Here

  private void addInstanceLens(Lens lens) {
    this._lenses.add(lens);
    this._all.put(lens.getIdentifier(), lens);

    for (Iterator<ISelector> di = lens.getDomainSet().iterator(); di.hasNext(); ) {
      ISelector domain = di.next();
      // TODO other valid selector types may need to be integrated, such as FSE/SPARQL selectors
      if (domain instanceof InstanceSelector) {
        InstanceSelector is = (InstanceSelector) domain;
        LensMatchSet lms = this._instanceLensMatches.getMatch(is.getInstance());
        if (null == lms) {
View Full Code Here

    // matches are found (all lenses are executed).
    Vector<Resource> validStarts = new Vector<Resource>();
    if (grouping.hasPrimaries()) {
      Iterator<ISelector> primariesIt = grouping.getPrimaries().iterator();
      while (primariesIt.hasNext()) {
        ISelector primary = primariesIt.next();
        if (primary.canSelectResources()) {
          try {
            Iterator<Resource> valids = primary.selectResources(in);
            while (valids.hasNext()) {
              validStarts.add(valids.next());
            }
          } catch (InvalidResultSetException e) {
            // not a valid exception at this point
          }
        }
      }
    } else {
      validStarts = null;
    }

    Iterator<Lens> li = grouping.getLenses().iterator();
    while (li.hasNext()) {
      Lens lens = li.next();
      Iterator<ISelector> di = lens.getDomainSet().iterator();
      while (di.hasNext()) {
        ISelector select = di.next();
        if (select.canSelectResources()) {
          try {
            Iterator<Resource> ri = select.selectResources(in);
            while (ri.hasNext()) {
              Resource res = (Resource) ri.next();
              if (null == validStarts || (null != validStarts && validStarts.contains(res))) {
                if (this._lensMatches.containsKey(res)) {
                  LensMatchSet match = this._lensMatches.getMatch(res);
View Full Code Here

    // matches are found (all lenses are executed).
    Vector<Resource> validStarts = new Vector<Resource>();
    if (grouping.hasPrimaries()) {
      Iterator<ISelector> primariesIt = grouping.getPrimaries().iterator();
      while (primariesIt.hasNext()) {
        ISelector primary = primariesIt.next();
        if (primary.canSelectResources()) {
          try {
            Iterator<Resource> valids = primary.selectResources(in);
            while (valids.hasNext()) {
              validStarts.add(valids.next());
            }
          } catch (InvalidResultSetException e) {
            // not a valid exception at this point
          }
        }
      }
    } else {
      validStarts = null;
    }

    LensMatchSet match = null;

    Iterator<Lens> li = grouping.getLenses().iterator();
    while (li.hasNext()) {
      Lens lens = li.next();
      Iterator<ISelector> di = lens.getDomainSet().iterator();
      while (di.hasNext()) {
        ISelector select = di.next();
        if (select.canSelectResources()) {
          if (select.canSelect(in, focus)) {
            if (null == validStarts || (null != validStarts && validStarts.contains(focus))) {
              if (this._lensMatches.containsKey(focus)) {
                match = this._lensMatches.getMatch(focus);
                match.add(lens);
              } else {
View Full Code Here

    while (fi.hasNext()) {
      Format format = fi.next();
     
      Iterator<ISelector> di = format.getDomainSet().iterator();
      while (di.hasNext()) {
        ISelector selects = di.next();
        if (selects.canSelectResources()) {
          /*
           * Only ClassFormat and InstanceFormat select resources,
           * so the vast amount of property formats can be skipped
           */
          if (!(format instanceof ClassFormat || format instanceof InstanceFormat))
            continue;
         
          try {
            Iterator<Resource> ri = selects.selectResources(in);
            while (ri.hasNext()) {
              Resource res = ri.next();
              if (this._formatResourceMatches.containsKey(res)) {
                ResourceFormatMatchSet match = this._formatResourceMatches.get(res);
                match.addClassFormat(format);
              } else {
                ResourceFormatMatchSet match = new ResourceFormatMatchSet(res);
                match.addClassFormat(format);
                this._formatResourceMatches.put(res, match);
              }
            }
          } catch (InvalidResultSetException e) {
            // TODO
          }
        } else if (selects.canSelectStatements()) {
          // inefficient - should really ask the model via sparql or something
          // about all the predicates it contains
          try {
            Iterator<Statement> si = selects.selectStatements(select.getModel(), null);
            while (si.hasNext()) {
              URI prop = si.next().getPredicate();
              if (this._formatPropertyMatches.containsKey(prop)) {
                PropertyFormatMatchSet match = this._formatPropertyMatches.get(prop);
                match.addPropertyFormat(format);
              } else {
                PropertyFormatMatchSet match = new PropertyFormatMatchSet(prop);
                match.addPropertyFormat(format);
                this._formatPropertyMatches.put(prop, match);
              }
            }
            si = selects.selectStatements(select.getNotModel(), null);
            while (si.hasNext()) {
              URI prop = si.next().getPredicate();
              if (this._formatPropertyMatches.containsKey(prop)) {
                PropertyFormatMatchSet match = this._formatPropertyMatches.get(prop);
                match.addPropertyFormat(format);
View Full Code Here

        if (primaryObj instanceof Resource && RDFList.isRDFList(in, (Resource) primaryObj)) {
          List primaries = new RDFList(in, (Resource) primaryObj).asJavaList();
          Iterator primaryDomains = primaries.iterator();
          while (primaryDomains.hasNext()) {
            Value domainNode = (Value) primaryDomains.next();
            ISelector domain = null;
            if (domainNode instanceof Resource) {
              // This is a type selector
              domain = new TypeSelector((Resource) domainNode);
            } else if (domainNode instanceof Literal) {
              Literal domainL = (Literal) domainNode;
View Full Code Here

     PropertySet finalProperties = resolvePropertySet(lens, in, focus);
    Iterator<ISelector> focusPSI = finalProperties.iterator();
    r.setTitle(resolveLabel(in, focus));
    this._resultModelHash.putResult(FresnelUtilities.dupResource(focus), r);
    while (focusPSI.hasNext()) {
      ISelector selector = focusPSI.next();
      if (selector.canSelectStatements()) {
        try {
          Iterator<Statement> selects = selector.selectStatements(in, focus);
          if (!selects.hasNext() &&
              (selector instanceof PropertySelector || selector instanceof PropertyDescription)) {
            if (selector instanceof PropertySelector) {
              URI predicate = ((PropertySelector) selector).getProperty();
              PropertyResult pr = r.getProperties().lookup(predicate);
              if (null == pr) {
                NoSuchPropertyResult nspr = new NoSuchPropertyResult(FresnelUtilities.dupURI(predicate), selector, r);
                nspr.setTitle(resolveLabel(in, predicate));
                r.addProperty(nspr);
                this._propertyResultModelHash.putResult(FresnelUtilities.dupURI(predicate), nspr);
                RepositoryConnection nconn = this._notModel.getConnection();
                nconn.add(FresnelUtilities.dupResource(focus), FresnelUtilities.dupURI(predicate), new LiteralImpl("empty"));
                nconn.close();
              } // if it's not null, there's nothing to do
            } else {
              Iterator<Statement> pi = ((PropertyDescription) selector).getProperty().selectStatements(in, focus);
              if (pi.hasNext()) {
                URI predicate = pi.next().getPredicate();
                PropertyResult pr = r.getProperties().lookup(predicate);
                if (null == pr) {
                  NoSuchPropertyResult nspr = new NoSuchPropertyResult(FresnelUtilities.dupURI(predicate), selector, r);
                  nspr.setTitle(resolveLabel(in, predicate));
                  r.addProperty(nspr);
                  this._propertyResultModelHash.putResult(FresnelUtilities.dupURI(predicate), nspr);
                  RepositoryConnection nconn = this._notModel.getConnection();
                  nconn.add(FresnelUtilities.dupResource(focus), FresnelUtilities.dupURI(predicate), new LiteralImpl("empty"));
                  nconn.close();
                } // if it's not null, there's nothing to do
              }
            }
          }
          while (selects.hasNext()) {
            Statement selected = selects.next();
            RepositoryConnection mconn = this._model.getConnection();
            mconn.add(selected.getSubject(), selected.getPredicate(), selected.getObject(), selected.getContext());
            mconn.commit();
            mconn.close();
            URI predicate;

            boolean inverse = !selected.getSubject().equals(focus);
            Value object = inverse ? selected.getSubject() : selected.getObject();

            if (selector instanceof PropertyDescription && ((PropertyDescription)selector).getProperty() instanceof FSESelector) {             
              predicate = new URIImpl("fsl://" + ((FSESelector)((PropertyDescription)selector).getProperty()).get_fse());
            }
            else
              predicate = selected.getPredicate();
           
            PropertyResult pr = r.getProperties().lookup(predicate, inverse);

            if (null == pr) {
              pr = new PropertyResult(FresnelUtilities.dupURI(predicate), selector, r, inverse);
              pr.setTitle(resolveLabel(in, predicate));
              r.addProperty(pr);
            //  this._propertyResultModelHash.putResult(FresnelUtilities.dupURI(predicate), pr);
            } else {
              // if somehow this property was already marked as NoSuchProperty, then
              // replace it with a real result
              if (!pr.isInModel()) {
                r.getProperties().removePropertyResult(pr);
                pr = new PropertyResult(FresnelUtilities.dupURI(predicate), selector, r);
                pr.setTitle(resolveLabel(in, predicate));
                r.addProperty(pr);
            //    this._propertyResultModelHash.putResult(FresnelUtilities.dupURI(predicate), pr);
              }
            }
           
            // cb  
            this._propertyResultModelHash.putResult(FresnelUtilities.dupURI(predicate), pr);
            if (object instanceof Resource) {
              Resource objResource = (Resource) object;
              Result subr = new Result(FresnelUtilities.dupResource(objResource), group, lens, in);
              Iterator<Statement> types = r.getTypesStatements();
              RepositoryConnection tmconn = this._typesModel.getConnection();
              tmconn.setAutoCommit(false);
              while(types.hasNext()) {
                Statement s = types.next();
                tmconn.add(s.getSubject(), s.getPredicate(), s.getObject(), s.getContext());
              }
              tmconn.commit();
              tmconn.setAutoCommit(true);
              tmconn.close();
              if (selector instanceof PropertyDescription) {
                PropertyDescription selectorPD = (PropertyDescription) selector;
                if (current == max) {
                  // if we've hit the limit, stop with sublensing
                  subr.setTitle(resolveLabel(in, objResource));
                } else {                 
                  // pick a sublens to apply to the resource
                  int newdepth = (selectorPD.getDepth() + current < max) ? selectorPD.getDepth() + current : max;
                  Lens sublens = null;
                  Iterator<Lens> sublensesIt = selectorPD.getSublensesIterator();
                  boolean match = false;
                  matched:
                  while (sublensesIt.hasNext()) {
                    sublens = sublensesIt.next();
                    Iterator<ISelector> domainIt = sublens.getDomainSet().iterator();
                    while (domainIt.hasNext()) {
                      ISelector subdomain = domainIt.next();
                      if (subdomain.canSelect(in, objResource)) {
                        subr = applyLens(group, in, sublens, objResource, current + 1, newdepth);
                        match = true;
                        break matched;
                      }
                    }
View Full Code Here

    }
    PropertySet finalProperties = resolvePropertySet(lens, in, focus);
    Iterator<ISelector> focusPSI = finalProperties.iterator();
    this._resultModelHash.putResult(FresnelUtilities.dupResource(focus), r);
    while (focusPSI.hasNext()) {
      ISelector selector = focusPSI.next();
      if (selector.canSelectStatements()) {
        try {
          Iterator<Statement> selects = selector.selectStatements(in, focus);
          while (selects.hasNext()) {
            Statement selected = selects.next();
            RepositoryConnection mconn = this._model.getConnection();
            mconn.add(FresnelUtilities.dupResource(selected.getSubject()),
                FresnelUtilities.dupURI(selected.getPredicate()),
                FresnelUtilities.dupValue(selected.getObject()));
            mconn.commit();
            mconn.close();
            URI prop = FresnelUtilities.dupURI(selected.getPredicate());
            Value object = selected.getObject();
            PropertyResult pr = r.getProperties().lookup(prop);
            if (null == pr) {
              pr = new PropertyResult(prop, selector, r);
              r.addProperty(pr);
            }
            if (object instanceof Resource) {
              Resource objResource = (Resource) object;
              if (selector instanceof PropertyDescription) {
                PropertyDescription selectorPD = (PropertyDescription) selector;
                if (current == max) {
                  ValueResult vr = new ValueResult(resolveLabel(in, objResource, false).getString(), pr, selected.getContext());
                  pr.addValue(vr);
                  this._propertyResultModelHash.putResult(prop, pr);
                } else {
                  // pick a sublens to apply to the resource
                  int newdepth = (selectorPD.getDepth() + current < max) ? selectorPD.getDepth() : max;
                  Lens sublens = null;
                  Iterator<Lens> sublensesIt = selectorPD.getSublensesIterator();
                  boolean matched = false;
                  matching:
                  while (sublensesIt.hasNext()) {
                    sublens = sublensesIt.next();
                    Iterator<ISelector> domainIt = sublens.getDomainSet().iterator();
                    while (domainIt.hasNext()) {
                      ISelector subdomain = domainIt.next();
                      if (subdomain.canSelect(in, objResource)) {
                        Result subr = applyLabelLens(sublens, in, objResource, current + 1, newdepth);
                        ValueResult vr = new ValueResult(subr, pr, selected.getContext());
                        pr.addValue(vr);
                        this._propertyResultModelHash.putResult(prop, pr);
                        matched = true;
View Full Code Here

TOP

Related Classes of edu.mit.simile.fresnel.selection.ISelector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.