Package org.openrdf.sesame.repository.local

Examples of org.openrdf.sesame.repository.local.LocalRepository


   *
   * @see org.corrib.s3b.mbb.service.MBBService#execute()
   */
  @Override
  public LocalRepository execute(LocalRepository inGraph) {
    LocalRepository lr = RepositoryFactory.getServiceRepository(this.getUri());
   
    //otherwise we need to execute the query
   
    boolean isNegation = MBBService.NEGATION.equals(this.params.get(1));
    boolean isInverse = MBBService.INVERSE.equals(this.params.get(2));
    String sProperty = this.params.get(3);
    String sValues = this.params.get(4);
   
    this.params.set(4, sValues);

    try {
      if(lr.getGraph().getStatements().hasNext())
        return lr;//it means that we already invoked this query
    } catch (AccessDeniedException e) {
      Repository.logger.warning(e.toString());
    }
   
    if(sValues == null || "".equals(sValues))
      sValues = "*";
   
    String[] aproperty = this.pproperty.getURI(sProperty);
    String pparam = "prop";// (!isNegation)?"<"+property+">":"prop";
//    String restparam = (!isNegation)?"(%1$s)":"NOT prop=<"+property+"> AND (%1$s)";
    String restparam = (isNegation)?"NOT (":"(";
    for(String s : aproperty){
      restparam += "prop = <"+s+"> OR ";
    }
    if(restparam.length() > 4)
      restparam = restparam.substring(0, restparam.length()-4);
    restparam += ")  AND (%1$s)";
   
    // --- =========== non inverse scenario ===================== ---
    RDFQuery rdfquery = (isInverse)?RDFQuery.RDFQ_INVERS_FILTER:RDFQuery.RDFQ_FILTER;
    String queryPart = rdfquery.toString(pparam,//we know the full URI of the property
                                restparam);//we only need to filter values
    String query = new ValueFilter(sValues).process(queryPart, this.isIgnoreCase());
    //no need for predefined properties

    Repository.logger.info(query);
   
    Value[] _uris;
    try {
      _uris = SesameWrapper.performDisjunctiveQuery(inGraph, lr.getGraph(), query);
      this.annotateResults(lr, _uris);
    } catch (AccessDeniedException e) {
      e.printStackTrace();
    }

View Full Code Here


    this.pnamespace = PredefinedNamespace.get();
  }

  @Override
  public LocalRepository execute(LocalRepository inGraph) {
    LocalRepository lr = RepositoryFactory.getServiceRepository(this.getUri());
   
   
    boolean isNegation = MBBService.NEGATION.equals(this.params.get(1));
    boolean isInverse = MBBService.INVERSE.equals(this.params.get(2));
    String sFullProperty = this.params.get(3);
    String sPropertyNS = this.params.get(4);
    String sPropertyName = this.params.get(5);
    String sValues = URLDecode.decode(this.params.get(6));
   
    this.params.set(6, sValues);
   
    boolean uriprop = (null == sPropertyNS || "".equals(sPropertyNS));
    String[] asFullProperty = null;
   
    if(uriprop) {
      if(null != sPropertyName && !"".equals(sPropertyName))
        sFullProperty = sPropertyName;
     
      sFullProperty = URLDecode.decode(sFullProperty);
      java.net.URI u;
      try {
        u = new java.net.URI(sFullProperty);
      } catch (URISyntaxException e) {
        u = null;
      }
     
//      if(u == null || !u.isAbsolute())
//        sFullProperty = this.pproperty.getURI(sFullProperty);
//     
//      String prop = this.pproperty.getName(sFullProperty);
     
      String prop;

      if(u == null || !u.isAbsolute()){
        asFullProperty = this.pproperty.getURI(sFullProperty); // if sFullProperty is a property name - get all URI
        prop = sFullProperty;
      } else {
        asFullProperty = new String[1];
        asFullProperty[0] = sFullProperty;
        prop = this.pproperty.getName(sFullProperty);
      }
     
      this.params.set(3, prop);
    }
   
    try {
      if(lr.getGraph().getStatements().hasNext())
        return lr;//it means that we already invoked this query
    } catch (AccessDeniedException e) {
      Repository.logger.warning(e.toString());
    }
    //otherwise we need to execute the query
   
    RDFQuery rdfquery;
    String pparam;
    String restparam;
    String using;
    String valueQueryPart;
   
    if(!"*".equals(sFullProperty)) {
      //this is the type of browse when you match values
      rdfquery  = (isInverse)?RDFQuery.RDFQ_BROWSE_LISTVALUES_PROPERTY_INVERSE:RDFQuery.RDFQ_BROWSE_LISTVALUES_PROPERTY;
      if(uriprop) {
        using = "";
//        pparam = "prop";//(isNegation)?"prop":"<"+sFullProperty+">";
        restparam = (isNegation)?"NOT (":"(";
        if(asFullProperty != null)
        for(String s : asFullProperty){
          restparam += "prop = <"+s+"> OR ";
        }
        if(restparam.length() > 4)
          restparam = restparam.substring(0, restparam.length()-4);
        restparam += ")";
      }else {
//        String property = this.pproperty.getURI(sPropertyName);
//        pparam = "prop";//(sPropertyNS == null)?"<"+property+">":"prop";
        restparam = "TRUE";
        if(!"*".equals(sPropertyNS))
          restparam += ((!isNegation)?" AND (":" AND (NOT ")+"namespace(prop) = property:";
        //namespace(prop) = property: AND localName(prop) LIKE "*digitaltype*" //IGNORE CASE
        if(!"*".equals(sPropertyName) && !"*".equals(sPropertyNS))
          restparam += (!isNegation)?" AND ":" OR ";
        if(!"*".equals(sPropertyName))
          restparam += ((!isNegation)?"":"NOT")+" localName(prop)=\""+sPropertyName+"\"";
        if(!"*".equals(sPropertyNS))
          restparam += ") ";

        String uprop = this.pnamespace.getURI(sPropertyNS);
        using = (sPropertyNS!=null && !"*".equals(sPropertyNS))?" USING NAMESPACE mbb = <http://s3b.corrib.org/mbb#>"+RDFQuery.RDFQ_ADD_NAMESPACE.toString((uprop==null)?"http://dummy.url/":uprop):"";
      }
     
      pparam = "prop";
     
      valueQueryPart = rdfquery.toString(restparam);

    }else {
      //this is the type of browse when you match properties
      rdfquery  = (isInverse)?RDFQuery.RDFQ_BROWSE_LISTVALUES_VALUE_INVERSE:RDFQuery.RDFQ_BROWSE_LISTVALUES_VALUE;
      pparam = "%1$s";
      restparam = "";
      using = "";
     
      valueQueryPart = rdfquery.toString("%1$s");
    }

    ValueFilter values = new ValueFilter(sValues);
    String valueSelectQuery = values.process(valueQueryPart, this.isIgnoreCase());
         valueSelectQuery += using;
    //no need for predefined properties
    Repository.logger.info(valueSelectQuery);
    Value[] avUris = SesameWrapper.performVectorQuery(inGraph, QueryLanguage.SERQL, valueSelectQuery);
   
    Set<Value> ssubjectUris = new HashSet<Value>();
    RDFQuery subjectRdfQuery;
    if(isInverse)
      subjectRdfQuery = (!"*".equals(sFullProperty))?RDFQuery.RDFQ_BROWSE_FILTEROBJECTS_INVERSE:RDFQuery.RDFQ_BROWSE_FILTEROBJECTS_VALUES_INVERSE;
    else
      subjectRdfQuery = (!"*".equals(sFullProperty))?RDFQuery.RDFQ_BROWSE_FILTEROBJECTS:RDFQuery.RDFQ_BROWSE_FILTEROBJECTS_VALUES;
    String subjectQueryPart;
    Value[] avResults;
   
    for(Value value : avUris) {
      String value_filter;
      if(value instanceof BNode)
        value_filter = "<_:"+value+">";
      else if(value instanceof URI)
        value_filter = "<"+value+">";
      else
        value_filter = "\""+value+"\"";
     
      if(!"*".equals(sFullProperty))
        subjectQueryPart = subjectRdfQuery.toString(pparam, ("".equals(restparam))?"TRUE":restparam,  value_filter);
      else {
        String tmpQ = subjectRdfQuery.toString(value_filter, "%1$s");
        subjectQueryPart = values.process(tmpQ, this.isIgnoreCase());
      }
      subjectQueryPart += using;

      avResults = SesameWrapper.performVectorQuery(Repository.MAIN_REPOSITORY.getLocalRepository(),
                                 QueryLanguage.SERQL,
                                 subjectQueryPart);
      ssubjectUris.addAll(Arrays.asList(avResults));
    }

    Value[] results = ssubjectUris.toArray(new Value[0]);
    try {
      SesameWrapper.loadResources(results, Repository.MAIN_REPOSITORY.getLocalRepository(), lr.getGraph());
    } catch (AccessDeniedException e) {
      e.printStackTrace();
    }
    this.annotateResults(lr, results);
   
View Full Code Here

*/
public class DisjunctionCombineService extends CombineService {

  @Override
  public LocalRepository execute(LocalRepository inGraph) {
    LocalRepository lr = RepositoryFactory.getServiceRepository(this.getUri());

    try {
      if (lr.getGraph().getStatements().hasNext())
        return lr;// it means that we already invoked this query
    } catch (AccessDeniedException e) {
      Repository.logger.warning(e.toString());
    }

    // otherwise we need to execute the query
    String service1Id = this.params.get(2);
    String service2Id = this.params.get(3);

    LocalRepository lr1 = ServiceById.getRepositoryByServiceId(service1Id);
    LocalRepository lr2 = ServiceById.getRepositoryByServiceId(service2Id);

    this.annotateResults(lr1, lr2, service1Id, service2Id);
   
    try {
      lr.addGraph(lr1.getGraph());
      lr.addGraph(lr2.getGraph());

    } catch (IOException e) {
      Repository.logger.warning("Could not access the graph: " + e);
    } catch (AccessDeniedException e) {
      Repository.logger.warning("Could not access the graph: " + e);
View Full Code Here

    this.params = new ArrayList<String>();
  }

  @Override
  public LocalRepository execute(LocalRepository inGraph) {
    LocalRepository lr = null;
    this.id = this.params.get(0);
    this.uri = getServiceUriById(this.id);
   
    lr = RepositoryFactory.getServiceRepository(uri);
   
    try {
      if(lr.getGraph().getStatements().hasNext())
        return lr;//it means that we already invoked this query
    } catch (AccessDeniedException e) {
      Repository.logger.warning(e.toString());
    }
   
View Full Code Here

    }else {
      String[] asparams = new String[7];
      BrowseSimilarService similarService = new BrowseSimilarService();
      ServiceChain newchain = null;
      LocalRepository simrepo;
      GraphStatistics graphstats;
      ValueStats aisize;
     
      try {
         newchain = (ServiceChain)this.callBean.getChain().clone();
         newchain.getServices().add(similarService);
      } catch (CloneNotSupportedException e) {
        e.printStackTrace();
      }
     
      similarService.setCallBean(this.getCallBean());
      similarService.setRequestParams(null);
      similarService.setUser(this.user);
 
      asparams[1] = "";//"!");
      asparams[2]= "";//"-");
      asparams[6]= "*";
     
     
      if(newchain != null)
        for(String property : results.keySet()) {
          String prop = property;
          String ns = null;
          String name = property;
         
          if(property.startsWith("-")) {
            asparams[2] =  MBBService.INVERSE;
            prop = property.substring(1);
            name = prop;
          }
         
          if(prop.indexOf(':')>0) {
            ns = prop.substring(0, prop.indexOf(':'));
            name = prop.substring(prop.indexOf(':')+1);
          }
         
          asparams[0]= this.params.get(0)+"/browse/"+property+"/*";
          asparams[3]= prop;
          asparams[4]= ns;
          asparams[5]= name;
         
          similarService.setUri(asparams[0]);
          similarService.setParams(Arrays.asList(asparams));
 
          simrepo = similarService.execute(repo);
          graphstats = GraphStatistics.get(simrepo.getGraph());
          graphstats.process(asparams[0], true, true, true);
         
          aisize = results.get(property);
          aisize.setCountWithResults(graphstats.getResults().size());
          aisize.setCountWithResources(graphstats.getResources().size());
View Full Code Here

     
    }else {
      String[] asprops = new String[6];
      BrowseRelatedService browseService = new BrowseRelatedService();
      ServiceChain newchain = null;
      LocalRepository simrepo;
      GraphStatistics graphstats;
      ValueStats aisize;
     
      try {
         newchain = (ServiceChain)this.callBean.getChain().clone();
         newchain.getServices().add(browseService);
      } catch (CloneNotSupportedException e) {
        e.printStackTrace();
      }
     
      browseService.setCallBean(this.getCallBean());
      browseService.setRequestParams(null);
      browseService.setUser(this.user);
 
      asprops[1]="";//"!");
      asprops[2]="";//"-");
     
     
      if(newchain != null)
        for(String property : results.keySet()) {
          String prop = property;
          String ns = null;
          String name = property;
         
          if(property.startsWith("-")) {
            asprops[2]=MBBService.INVERSE;
            prop = property.substring(1);
            name = prop;
          }
         
          if(prop.indexOf(':')>0) {
            ns = prop.substring(0, prop.indexOf(':'));
            name = prop.substring(prop.indexOf(':')+1);
          }
         
          asprops[0]=this.params.get(0)+"/browse/"+property+"$";
          asprops[3]=prop;
          asprops[4]=ns;
          asprops[5]=name;
 
          browseService.setParams(Arrays.asList(asprops));
          browseService.setUri(asprops[0]);
 
          simrepo = browseService.execute(repo);
          graphstats = GraphStatistics.get(simrepo.getGraph());
          graphstats.process(asprops[0], true, true, true);
         
          aisize = results.get(property);
          aisize.setCountWithResults(graphstats.getResults().size());
          aisize.setCountWithResources(graphstats.getResources().size());
View Full Code Here

      }catch(NullPointerException ex) {
        ex.printStackTrace();
      }
     
    }else {
      LocalRepository lr = RepositoryFactory.createTempRepository();
      String prop = "";
     
      for(URI s : aproperty){
        prop += "prop = <"+s.getURI()+"> OR ";
      }
      if(prop.length() > 4)
        prop = prop.substring(0, prop.length()-4);

      String lit;
      GraphStatistics gstats;
      Value[] ares;
      RDFQuery query = (inverse)?RDFQuery.RDFQ_STATS_GETRES_BY_VALUE_INV:RDFQuery.RDFQ_STATS_GETRES_BY_VALUE;
     
      for(ValueStats value : result.values()) {
        lit = "\""+value.getLiteral().getLabel()+"\"";
        if(value.getLiteral().getLanguage() != null)
          lit += "@"+value.getLiteral().getLanguage();
        else if(value.getLiteral().getDatatype() != null)
          lit += "^^<"+value.getLiteral().getDatatype()+">";
       
        try {
          ares = SesameWrapper.performVectorQuery(repo, query, prop, lit);
          SesameWrapper.loadResources(ares, repo, lr.getGraph());
         
          gstats = GraphStatistics.get(lr.getGraph());
          gstats.forceProcess(null, true, true, true);
         
          value.setCountWithBnodes(gstats.getBnodes().size());
          value.setCountWithResources(gstats.getResources().size());
          value.setCountWithResults(gstats.getResults().size());
         
          lr.clear(new StdOutAdminListener());
        }catch(Exception ex) {
          Repository.logger.warning("Something wrong has happend: "+ex);
        }
      }
    }//--check if full processing allowed   
View Full Code Here

     
    }else {
      BrowseSimilarService similarService = new BrowseSimilarService();
      String[] asparams = new String[7];
      ServiceChain newchain = null;
      LocalRepository simrepo;
      GraphStatistics graphstats;
      String[] aprop = (aproperty != null && aproperty.length > 0)?PredefinedProperty.shortenURI(aproperty[0]):null; //XXX this is a nasty quick hack - to be corrected later
     
      try {
         newchain = (ServiceChain)this.callBean.getChain().clone();
         newchain.getServices().add(similarService);
      } catch (CloneNotSupportedException e) {
        e.printStackTrace();
      }
     
      similarService.setCallBean(this.getCallBean());
      similarService.setRequestParams(null);
      similarService.setUser(this.user);
 
      asparams[1]= "";//"!";
      asparams[2]= (inverse)?"-":"";//"-";
      asparams[3]= (aprop != null)?aprop[3]:"*";
      asparams[4]= (aprop != null && aprop[1]!=null)?aprop[1]:"";
      asparams[5]= (aprop != null && aprop[2]!=null)?aprop[2]:((aprop != null)?aprop[0]:"");
     
     
      if(newchain != null)
        for(ValueStats value : results.values()) {
          String lit = value.getLiteral().getLabel();
         
          if(lit.indexOf(' ') > 0)
            lit = "\""+lit.replaceAll(" ", "%20")+"\"";
         
          asparams[0] = this.params.get(0)+"/similar/"+((inverse)?"-":"")+asparams[3]+"/"+lit;
          asparams[6]= lit;
 
          similarService.setParams(Arrays.asList(asparams));
          similarService.setUri(asparams[0]);
         
          simrepo = similarService.execute(repo);
          graphstats = GraphStatistics.get(simrepo.getGraph());
          graphstats.process(asparams[0], true, true, true);
         
          value.setCountWithResults(graphstats.getResults().size());
          value.setCountWithResources(graphstats.getResources().size());
          value.setCountWithBnodes(graphstats.getBnodes().size());
View Full Code Here

   *
   * @see org.corrib.s3b.mbb.service.MBBService#execute()
   */
  @Override
  public LocalRepository execute(LocalRepository inGraph) {
    LocalRepository lr = RepositoryFactory.getServiceRepository(this.getUri());
   
   
    boolean isNegation = MBBService.NEGATION.equals(this.params.get(1));
    boolean isInverse = MBBService.INVERSE.equals(this.params.get(2));
    String sPropertyNamespace = this.params.get(3);
    String sPropertyName = this.params.get(4);
    String sValues = URLDecode.decode(this.params.get(5));
   
    this.params.set(5, sValues);

    try {
      if(lr.getGraph().getStatements().hasNext())
        return lr;//it means that we already invoked this query
    } catch (AccessDeniedException e) {
      Repository.logger.warning(e.toString());
    }
    //otherwise we need to execute the query
   
   
    if(("".equals(sPropertyName) || sPropertyName == null) && "*".equals(sPropertyNamespace)) {
      sPropertyName = "*";
      this.params.set(3, "*");
    }
   
    // --- non inverse scenario ---
    //we only need to filter values
    String props = "(%1$s)";
    if(!"*".equals(sPropertyNamespace))
      props += ((!isNegation)?" AND (":" AND (NOT ")+"namespace(prop) = property:";
    //namespace(prop) = property: AND localName(prop) LIKE "*digitaltype*" //IGNORE CASE
    if(!"*".equals(sPropertyName) && !"*".equals(sPropertyNamespace))
      props += (!isNegation)?" AND ":" OR ";
    if(!"*".equals(sPropertyName))
      props += ((!isNegation)?"":"NOT")+" localName(prop)=\""+sPropertyName+"\"";
    if(!"*".equals(sPropertyNamespace))
      props += ") ";
       
    //we need it only when namespace defined
    RDFQuery rdfquery = (isInverse)?RDFQuery.RDFQ_INVERS_FILTER:RDFQuery.RDFQ_FILTER;
    String queryPart = rdfquery.toString("prop",//just prop
                             props);//we only need to filter values
    String query = new ValueFilter(sValues).process(queryPart, this.isIgnoreCase());
    if(!"*".equals(sPropertyNamespace))
       query += " USING NAMESPACE mbb = <http://s3b.corrib.org/mbb#>"+RDFQuery.RDFQ_ADD_NAMESPACE.toString(this.pnamespace.getURI(sPropertyNamespace));

    Repository.logger.info("CustomPropertyFilterService: "+query);
   
    Value[] results;
    try {
      results = SesameWrapper.performDisjunctiveQuery(inGraph, lr.getGraph(), query);
      this.annotateResults(lr, results);
    } catch (AccessDeniedException e) {
      e.printStackTrace();
    }
   
View Full Code Here

  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    ServletCallBean bean = (ServletCallBean)request.getAttribute("callBean");   
    String dispatcherUrl = null;
   
    if(bean != null) {
      LocalRepository repo = bean.getRepository();
     
      try {
        dispatcherUrl = ((StatsMetaService)bean.getChain().getMetaservice()).executeStats(repo);
      } catch (AccessDeniedException e) {
        response.sendError(500, "Graph access problem: "+e);
View Full Code Here

TOP

Related Classes of org.openrdf.sesame.repository.local.LocalRepository

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.