org.aksw.simba.largerdfbench.util

## Class Selectivity

- java.lang.Object
- - org.aksw.simba.largerdfbench.util.Selectivity

-     public class Selectivity
      extends java.lang.Object

  Dataset-restricted Triple pattern selectivities.
  Author:
    Saleem

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static org.openrdf.repository.RepositoryConnection` | `con`
    `static int` | `maxRunTime`
    `static java.io.BufferedWriter` | `toBW`
    `static java.util.HashMap<java.lang.String,java.lang.Double>` | `tpSelCache`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Selectivity()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static long` | `getEndpointTotalTriples(java.lang.String endpoint, java.lang.String graph)` Get dataset/endpoint total number of triples
    `static double` | `getMeanTriplePatternSelectivity(java.lang.String query, java.lang.String endpoint, java.lang.String graph, java.lang.Long endpointSize)` get Mean Triple pattern selectivity
    `static java.lang.String` | `getObject(org.openrdf.query.algebra.StatementPattern stmt)` Get object from triple pattern
    `static java.lang.String` | `getObjectVertexLabel(org.openrdf.query.algebra.StatementPattern stmt)` Get label for the object vertex of a triple pattern
    `static java.lang.String` | `getPredicate(org.openrdf.query.algebra.StatementPattern stmt)` Get Predicate from triple pattern
    `static java.lang.String` | `getPredicateVertexLabel(org.openrdf.query.algebra.StatementPattern stmt)` Get label for the predicate vertex of a triple pattern
    `static long` | `getQueryResultSize(java.lang.String queryStr, java.lang.String endpoint, java.lang.String sesameQueryType)` Get the result Size of the query
    `static java.lang.String` | `getQueryString(org.openrdf.query.algebra.StatementPattern stmt, java.lang.String tp, java.lang.String graph)` Get query to the count of results against triple pattern
    `static java.lang.String` | `getSubject(org.openrdf.query.algebra.StatementPattern stmt)` Get subject from triple pattern
    `static java.lang.String` | `getSubjectVertexLabel(org.openrdf.query.algebra.StatementPattern stmt)` Get label for the subject vertex of a triple pattern
    `static java.lang.String` | `getTriplePattern(org.openrdf.query.algebra.StatementPattern stmt)` Get triple pattern from statement pattern
    `static double` | `getTriplePatternSelectivity(org.openrdf.query.algebra.StatementPattern stmt, java.lang.String tp, java.lang.String endpoint, java.lang.String graph, long endpointSize)` Get Triple pattern selectivity
    `static void` | `initializeRepoConnection(java.lang.String endpointUrl)` Initialize repository for a SPARQL endpoint
    `static void` | `main(java.lang.String[] args)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### con

          public static org.openrdf.repository.RepositoryConnection con

    - #### tpSelCache

          public static java.util.HashMap<java.lang.String,java.lang.Double> tpSelCache

    - #### maxRunTime

          public static int maxRunTime

    - #### toBW

          public static java.io.BufferedWriter toBW

  - ### Constructor Detail

    - #### Selectivity

          public Selectivity()

  - ### Method Detail

    - #### main

          public static void main(java.lang.String[] args)
                           throws org.openrdf.repository.RepositoryException,
                                  org.openrdf.query.MalformedQueryException,
                                  org.openrdf.query.QueryEvaluationException,
                                  java.io.IOException

      Throws:
        `org.openrdf.repository.RepositoryException`
        `org.openrdf.query.MalformedQueryException`
        `org.openrdf.query.QueryEvaluationException`
        `java.io.IOException`

    - #### getQueryResultSize

          public static long getQueryResultSize(java.lang.String queryStr,
                                                java.lang.String endpoint,
                                                java.lang.String sesameQueryType)
                                         throws org.openrdf.repository.RepositoryException,
                                                org.openrdf.query.MalformedQueryException,
                                                java.io.IOException

      Get the result Size of the query
      Parameters:
        `queryStr` - SPARQL query
        `endpoint` - SPARQL endpoint
        `sesameQueryType` - Query Type (ask, select, describe, construct )
      Returns:
        totalSize Result size
      Throws:
        `org.openrdf.repository.RepositoryException`
        `org.openrdf.query.MalformedQueryException`
        `java.io.IOException`

    - #### getMeanTriplePatternSelectivity

          public static double getMeanTriplePatternSelectivity(java.lang.String query,
                                                               java.lang.String endpoint,
                                                               java.lang.String graph,
                                                               java.lang.Long endpointSize)
                                                        throws org.openrdf.query.MalformedQueryException,
                                                               org.openrdf.repository.RepositoryException,
                                                               org.openrdf.query.QueryEvaluationException

      get Mean Triple pattern selectivity
      Parameters:
        `query` - SPARQL query
        `endpointSize` - Total number of triples patterns in the endpoint
        `endpoint` - Endpoint Url
        `graph` - Default graph can be null
      Returns:
        meanQrySel Mean triple pattern selectivity across complete query
      Throws:
        `org.openrdf.query.MalformedQueryException`
        `org.openrdf.query.QueryEvaluationException`
        `org.openrdf.repository.RepositoryException`

    - #### getEndpointTotalTriples

          public static long getEndpointTotalTriples(java.lang.String endpoint,
                                                     java.lang.String graph)
                                              throws org.openrdf.repository.RepositoryException,
                                                     org.openrdf.query.MalformedQueryException,
                                                     org.openrdf.query.QueryEvaluationException

      Get dataset/endpoint total number of triples
      Parameters:
        `endpoint` - SPARQL endpoint
        `graph` - Named Graph, can be null
      Returns:
        totalSize Total size
      Throws:
        `org.openrdf.repository.RepositoryException`
        `org.openrdf.query.MalformedQueryException`
        `org.openrdf.query.QueryEvaluationException`

    - #### getTriplePatternSelectivity

          public static double getTriplePatternSelectivity(org.openrdf.query.algebra.StatementPattern stmt,
                                                           java.lang.String tp,
                                                           java.lang.String endpoint,
                                                           java.lang.String graph,
                                                           long endpointSize)
                                                    throws org.openrdf.repository.RepositoryException,
                                                           org.openrdf.query.MalformedQueryException,
                                                           org.openrdf.query.QueryEvaluationException

      Get Triple pattern selectivity
      Parameters:
        `stmt` - Statement pattern
        `tp` - triples representation of statement pattern
        `endpoint` - Endpoint Url
        `graph` - Default graph can be null
        `endpointSize` - Total number of triples in the endpoint
      Returns:
        Selectivity of the filtered triple pattern
      Throws:
        `org.openrdf.repository.RepositoryException`
        `org.openrdf.query.MalformedQueryException`
        `org.openrdf.query.QueryEvaluationException`

    - #### getTriplePattern

          public static java.lang.String getTriplePattern(org.openrdf.query.algebra.StatementPattern stmt)

      Get triple pattern from statement pattern
      Parameters:
        `stmt` - Statement pattern
      Returns:
        triplePattern Triple pattern

    - #### getQueryString

          public static java.lang.String getQueryString(org.openrdf.query.algebra.StatementPattern stmt,
                                                        java.lang.String tp,
                                                        java.lang.String graph)

      Get query to the count of results against triple pattern
      Parameters:
        `stmt` - Triple pattern
        `tp` - Triple pattern as key for stmtFilters hash map. For checking whether stmt should contain Filter clause as well
        `graph` - Default graph can be null
      Returns:
        query SPARQL query

    - #### getPredicate

          public static java.lang.String getPredicate(org.openrdf.query.algebra.StatementPattern stmt)

      Get Predicate from triple pattern
      Parameters:
        `stmt` - Triple pattern
      Returns:
        tuple Subject tuple

    - #### getObject

          public static java.lang.String getObject(org.openrdf.query.algebra.StatementPattern stmt)

      Get object from triple pattern
      Parameters:
        `stmt` - Triple pattern
      Returns:
        tuple Subject tuple

    - #### getSubject

          public static java.lang.String getSubject(org.openrdf.query.algebra.StatementPattern stmt)

      Get subject from triple pattern
      Parameters:
        `stmt` - Triple pattern
      Returns:
        tuple Subject tuple

    - #### getObjectVertexLabel

          public static java.lang.String getObjectVertexLabel(org.openrdf.query.algebra.StatementPattern stmt)

      Get label for the object vertex of a triple pattern
      Parameters:
        `stmt` - triple pattern
      Returns:
        label Vertex label

    - #### getPredicateVertexLabel

          public static java.lang.String getPredicateVertexLabel(org.openrdf.query.algebra.StatementPattern stmt)

      Get label for the predicate vertex of a triple pattern
      Parameters:
        `stmt` - triple pattern
      Returns:
        label Vertex label

    - #### getSubjectVertexLabel

          public static java.lang.String getSubjectVertexLabel(org.openrdf.query.algebra.StatementPattern stmt)

      Get label for the subject vertex of a triple pattern
      Parameters:
        `stmt` - triple pattern
      Returns:
        label Vertex label

    - #### initializeRepoConnection

          public static void initializeRepoConnection(java.lang.String endpointUrl)
                                               throws org.openrdf.repository.RepositoryException

      Initialize repository for a SPARQL endpoint
      Parameters:
        `endpointUrl` - Endpoint Url
      Throws:
        `org.openrdf.repository.RepositoryException`