pitt.search.semanticvectors.vectors.ZeroVectorException Java Examples

The following examples show how to use pitt.search.semanticvectors.vectors.ZeroVectorException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PsiUtils.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Prints the nearest predicate for a particular flagConfig. (Please extend this comment!)
 *
 * @param flagConfig
 * @throws IOException
 */
public static void printNearestPredicate(FlagConfig flagConfig) throws IOException {
  VerbatimLogger.info("Printing predicate results.");
  Vector queryVector = VectorFactory.createZeroVector(flagConfig.vectortype(), flagConfig.dimension());
  VectorSearcher.VectorSearcherBoundProduct predicateFinder;
  try {
    predicateFinder = new VectorSearcher.VectorSearcherBoundProduct(
        VectorStoreReader.openVectorStore(flagConfig.semanticvectorfile(), flagConfig),
        VectorStoreReader.openVectorStore(flagConfig.boundvectorfile(), flagConfig),
        null, flagConfig, queryVector);
    List<SearchResult> bestPredicate = predicateFinder.getNearestNeighbors(1);
    if (bestPredicate.size() > 0) {
      String pred = bestPredicate.get(0).getObjectVector().getObject().toString();
      System.out.println(pred);
    }
  } catch (ZeroVectorException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
}
 
Example #2
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param queryVecStore Vector store to use for query generation.
 * @param searchVecStore The vector store to search.
 * @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
 * @param queryTerms Terms that will be parsed and used to generate a query subspace.
 */
public VectorSearcherMaxSim(VectorStore queryVecStore,
    VectorStore searchVecStore,
    LuceneUtils luceneUtils,
    FlagConfig flagConfig,
    String[] queryTerms)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);
  this.disjunctVectors = new ArrayList<Vector>();

  for (int i = 0; i < queryTerms.length; ++i) {
    // There may be compound disjuncts, e.g., "A NOT B" as a single argument.
    String[] tmpTerms = queryTerms[i].split("\\s");
    Vector tmpVector = CompoundVectorBuilder.getQueryVector(
        queryVecStore, luceneUtils, flagConfig, tmpTerms);

    if (tmpVector != null) {
      this.disjunctVectors.add(tmpVector);
    }
  }
  if (this.disjunctVectors.size() == 0) {
    throw new ZeroVectorException("No nonzero input vectors ... no results.");
  }
}
 
Example #3
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param queryVecStore Vector store to use for query generation.
 * @param searchVecStore The vector store to search.
 * @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
 * @param queryTerms Terms that will be parsed and used to generate a query subspace.
 */
public VectorSearcherMaxSim(VectorStore queryVecStore,
    VectorStore searchVecStore,
    LuceneUtils luceneUtils,
    FlagConfig flagConfig,
    Vector[] queryTerms)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);
  this.disjunctVectors = new ArrayList<Vector>();

  for (int i = 0; i < queryTerms.length; ++i) {
    // There may be compound disjuncts, e.g., "A NOT B" as a single argument.
    Vector tmpVector = queryTerms[i];

    if (tmpVector != null) {
      this.disjunctVectors.add(tmpVector);
    }
  }
  if (this.disjunctVectors.size() == 0) {
    throw new ZeroVectorException("No nonzero input vectors ... no results.");
  }
}
 
Example #4
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param queryVecStore Vector store to use for query generation.
 * @param searchVecStore The vector store to search.
 * @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
 * @param queryTerms Terms that will be parsed and used to generate a query subspace.
 */
public VectorSearcherMinSim(VectorStore queryVecStore,
    VectorStore searchVecStore,
    LuceneUtils luceneUtils,
    FlagConfig flagConfig,
    String[] queryTerms)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);
  this.disjunctVectors = new ArrayList<Vector>();

  for (int i = 0; i < queryTerms.length; ++i) {
    // There may be compound disjuncts, e.g., "A NOT B" as a single argument.
    String[] tmpTerms = queryTerms[i].split("\\s");
    Vector tmpVector = CompoundVectorBuilder.getQueryVector(
        queryVecStore, luceneUtils, flagConfig, tmpTerms);

    if (tmpVector != null) {
      this.disjunctVectors.add(tmpVector);
    }
  }
  if (this.disjunctVectors.size() == 0) {
    throw new ZeroVectorException("No nonzero input vectors ... no results.");
  }
}
 
Example #5
Source File: SemVectorsPeer.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
private LinkedList<SearchResult> search(String query,VectorStore queryStore,VectorStore searchStore,int numResults)
{
	 VectorSearcher vecSearcher;
	 LinkedList<SearchResult> results = new LinkedList<>();
	 try 
	 {
		 String[] queryTerms = query.split("\\s+");
		 vecSearcher =
	            new VectorSearcher.VectorSearcherCosine(queryStore,
	                                                    searchStore,
	                                                    luceneUtils,
	                                                    flagConfig,
	                                                    queryTerms);
		 results = vecSearcher.getNearestNeighbors(numResults);
		 
		 
	 } catch (pitt.search.semanticvectors.vectors.ZeroVectorException e) {
		 results = new LinkedList<>();

	}
	 return results;
}
 
Example #6
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param queryVecStore Vector store to use for query generation.
 * @param searchVecStore The vector store to search.
 * @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
 * @param queryTerms Terms that will be parsed and used to generate a query subspace.
 */
public VectorSearcherMinSim(VectorStore queryVecStore,
    VectorStore searchVecStore,
    LuceneUtils luceneUtils,
    FlagConfig flagConfig,
    Vector[] queryTerms)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);
  this.disjunctVectors = new ArrayList<Vector>();

  for (int i = 0; i < queryTerms.length; ++i) {
    // There may be compound disjuncts, e.g., "A NOT B" as a single argument.
    Vector tmpVector = queryTerms[i];

    if (tmpVector != null) {
      this.disjunctVectors.add(tmpVector);
    }
  }
  if (this.disjunctVectors.size() == 0) {
    throw new ZeroVectorException("No nonzero input vectors ... no results.");
  }
}
 
Example #7
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param queryVecStore Vector store to use for query generation.
 * @param searchVecStore The vector store to search.
 * @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
 * @param queryTerms Terms that will be parsed into a query
 * expression. If the string "?" appears, terms best fitting into this position will be returned
 */
public VectorSearcherPerm(VectorStore queryVecStore,
    VectorStore searchVecStore,
    LuceneUtils luceneUtils,
    FlagConfig flagConfig,
    String[] queryTerms)
        throws IllegalArgumentException, ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);

  try {
    theAvg = pitt.search.semanticvectors.CompoundVectorBuilder.
        getPermutedQueryVector(queryVecStore, luceneUtils, flagConfig, queryTerms);
  } catch (IllegalArgumentException e) {
    logger.info("Couldn't create permutation VectorSearcher ...");
    throw e;
  }

  if (theAvg.isZeroVector()) {
    throw new ZeroVectorException("Permutation query vector is zero ... no results.");
  }
}
 
Example #8
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param queryVecStore Vector store to use for query generation (this is also reversed).
 * @param searchVecStore The vector store to search (this is also reversed).
 * @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
 * @param queryTerms Terms that will be parsed into a query
 * expression. If the string "?" appears, terms best fitting into this position will be returned
 */
public BalancedVectorSearcherPerm(
    VectorStore queryVecStore, VectorStore searchVecStore, LuceneUtils luceneUtils,
    FlagConfig flagConfig, String[] queryTerms)
        throws IllegalArgumentException, ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);
  specialFlagConfig = flagConfig;
  specialLuceneUtils = luceneUtils;
  try {
    oneDirection = pitt.search.semanticvectors.CompoundVectorBuilder.
        getPermutedQueryVector(queryVecStore, luceneUtils, flagConfig, queryTerms);
    otherDirection = pitt.search.semanticvectors.CompoundVectorBuilder.
        getPermutedQueryVector(searchVecStore, luceneUtils, flagConfig, queryTerms);
  } catch (IllegalArgumentException e) {
    logger.info("Couldn't create balanced permutation VectorSearcher ...");
    throw e;
  }

  if (oneDirection.isZeroVector()) {
    throw new ZeroVectorException("Permutation query vector is zero ... no results.");
  }
}
 
Example #9
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
  * Lucene search, no semantic vectors required
  * @param luceneUtils LuceneUtils object to use for query weighting. (May not be null.)
  * @param queryTerms Terms that will be parsed into a query expression
  */
 public VectorSearcherLucene(LuceneUtils luceneUtils,
     FlagConfig flagConfig, String[] queryTerms)
         throws IllegalArgumentException, ZeroVectorException {
   
  super(null, null, luceneUtils, flagConfig);
  this.specialLuceneUtils = luceneUtils;
  this.specialFlagConfig = flagConfig;
  Directory dir;
try {
	dir = FSDirectory.open(FileSystems.getDefault().getPath(flagConfig.luceneindexpath()));
	this.iSearcher = new IndexSearcher(DirectoryReader.open(dir));
    
	if (!flagConfig.elementalvectorfile().equals("elementalvectors"))
	{this.acceptableTerms = new VectorStoreRAM(flagConfig);
    acceptableTerms.initFromFile(flagConfig.elementalvectorfile());
	}
} catch (IOException e) {
	logger.info("Lucene index initialization failed: "+e.getMessage());
}
  
  this.queryTerms = queryTerms;
  
 }
 
Example #10
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public VectorSearcherBoundProduct(VectorStore queryVecStore, VectorStore boundVecStore,
    VectorStore searchVecStore, LuceneUtils luceneUtils, FlagConfig flagConfig, ArrayList<Vector> incomingVectors)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);

  Vector theSuperposition = VectorFactory.createZeroVector(
      flagConfig.vectortype(), flagConfig.dimension());

  for (int q = 0; q < incomingVectors.size(); q++)
    theSuperposition.superpose(incomingVectors.get(q), 1, null);

  theSuperposition.normalize();
  this.queryVector = theSuperposition;

  if (this.queryVector.isZeroVector()) {
    throw new ZeroVectorException("Query vector is zero ... no results.");
  }
}
 
Example #11
Source File: SemanticVectorsStore.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
/**
 * Find similar users by querying the docstore using a query from the terms passed in
 * @param <T>
 * @param terms
 * @param lUtils : lucene utils
 * @param numResults : max number of results to return
 * @param docResult : the result list of return ids T
 * @param docTransform : the transform from document to return id type T
 */
public <T extends Comparable<T>> void findSimilarUsersFromTerms(String[] terms,LuceneUtils lUtils,int numResults,ArrayList<SemVectorResult<T>> docResult,QueryTransform<T> docTransform)
{
	List<SearchResult> results;
	try 
	{
		VectorSearcher vecSearcher =
	            new VectorSearcher.VectorSearcherCosine(termVecReader,
	                                                    docVecReader,
	                                                    luceneUtils,
	                                                    flagConfig,
	                                                    terms);
		results = vecSearcher.getNearestNeighbors(numResults);
	} 
	catch (pitt.search.semanticvectors.vectors.ZeroVectorException e) {
		results = new LinkedList<>();
	}
	for(SearchResult r : results)
	{
		String filename = r.getObjectVector().getObject().toString();
		
		docResult.add(new SemVectorResult<>(docTransform.fromSV(filename),r.getScore()));
	}
}
 
Example #12
Source File: SemanticVectorsStore.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
private LinkedList<SearchResult> recommend(String query,VectorStore queryStore,VectorStore searchStore,int numResults,Set<String> exclusions,Set<String> inclusions,String minDoc)
{

	 LinkedList<SearchResult> results = new LinkedList<>();
	 try 
	 {
		 String[] queryTerms = query.split("\\s+");
		 VectorStoreRecommender vecSearcher =
	            new VectorStoreRecommender.VectorStoreRecommenderCosine(queryStore,
	                                                    searchStore,
	                                                    luceneUtils,
	                                                    queryTerms,
	                                                    exclusions,
	                                                    inclusions,
	                                                    minDoc);
		 results = vecSearcher.getNearestNeighbors(numResults);
		 
		 
	 } catch (ZeroVectorException e) {
		 results = new LinkedList<>();
	}
	 finally{}
	 return results;
}
 
Example #13
Source File: SemanticVectorsStore.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
private LinkedList<SearchResult> search(String query,VectorStore queryStore,VectorStore searchStore,int numResults)
{
	 VectorSearcher vecSearcher;
	 LinkedList<SearchResult> results = new LinkedList<>();
	 try 
	 {
		 String[] queryTerms = query.split("\\s+");
		 vecSearcher =
	            new VectorSearcher.VectorSearcherCosine(queryStore,
	                                                    searchStore,
	                                                    luceneUtils,
	                                                    flagConfig,
	                                                    queryTerms);
		 results = vecSearcher.getNearestNeighbors(numResults);
		 
		 
	 } catch (pitt.search.semanticvectors.vectors.ZeroVectorException e) {
		 results = new LinkedList<>();

	}
	 return results;
}
 
Example #14
Source File: VectorStoreRecommender.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
/**
 * @param queryVecStore Vector store to use for query generation.
 * @param searchVecStore The vector store to search.
 * @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
 * @param queryTerms Terms that will be parsed into a query
 * expression. If the string "NOT" appears, terms after this will be negated.
 */
public VectorStoreRecommenderCosine(VectorStore queryVecStore,
                            VectorStore searchVecStore,
                            LuceneUtils luceneUtils,
                            String[] queryTerms,
                            Set<String> exclusions,
                            Set<String> inclusions,
                            String minDoc)
    throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, exclusions,inclusions,minDoc);
  this.queryVector = CompoundVectorBuilder.getQueryVector(queryVecStore,
                                                          luceneUtils,
                                                          FlagConfig.getFlagConfig(null),
                                                          queryTerms);
  if (this.queryVector.isZeroVector()) {
    throw new ZeroVectorException("Query vector is zero ... no results.");
  }
}
 
Example #15
Source File: SemVectorsPeer.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
/**
 * Find similar users by querying the docstore using a query from the terms passed in
 * @param <T>
 * @param terms
 * @param lUtils : lucene utils
 * @param numResults : max number of results to return
 * @param docResult : the result list of return ids T
 * @param docTransform : the transform from document to return id type T
 */
public <T extends Comparable<T>> void findSimilarUsersFromTerms(String[] terms,LuceneUtils lUtils,int numResults,ArrayList<SemVectorResult<T>> docResult,QueryTransform<T> docTransform)
{
	List<SearchResult> results;
	try 
	{
		VectorSearcher vecSearcher =
	            new VectorSearcher.VectorSearcherCosine(termVecReader,
	                                                    docVecReader,
	                                                    luceneUtils,
	                                                    flagConfig,
	                                                    terms);
		results = vecSearcher.getNearestNeighbors(numResults);
	} 
	catch (pitt.search.semanticvectors.vectors.ZeroVectorException e) {
		results = new LinkedList<>();
	}
	for(SearchResult r : results)
	{
		String filename = r.getObjectVector().getObject().toString();
		
		docResult.add(new SemVectorResult<>(docTransform.fromSV(filename),r.getScore()));
	}
}
 
Example #16
Source File: SemVectorsPeer.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
private LinkedList<SearchResult> recommend(String query,VectorStore queryStore,VectorStore searchStore,int numResults,Set<String> exclusions,Set<String> inclusions,String minDoc)
{

	 LinkedList<SearchResult> results = new LinkedList<>();
	 try 
	 {
		 String[] queryTerms = query.split("\\s+");
		 VectorStoreRecommender vecSearcher =
	            new VectorStoreRecommender.VectorStoreRecommenderCosine(queryStore,
	                                                    searchStore,
	                                                    luceneUtils,
	                                                    queryTerms,
	                                                    exclusions,
	                                                    inclusions,
	                                                    minDoc);
		 results = vecSearcher.getNearestNeighbors(numResults);
		 
		 
	 } catch (ZeroVectorException zve) {
		 results = new LinkedList<>();
	 }
	 return results;
}
 
Example #17
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public VectorSearcherBoundMinimum(VectorStore elementalVecStore, VectorStore semanticVecStore, VectorStore predicateVecStore, 
    VectorStore searchVecStore, LuceneUtils luceneUtils, FlagConfig flagConfig, String term1)
        throws ZeroVectorException {
  super(semanticVecStore, searchVecStore, luceneUtils, flagConfig);

 this.disjunctSpace =  CompoundVectorBuilder.getBoundProductQuerySubspaceFromString(flagConfig, elementalVecStore, semanticVecStore, predicateVecStore, term1);
}
 
Example #18
Source File: PSITypeLister.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws IOException, ZeroVectorException {
  PSITypeLister typeLister = new PSITypeLister(args);

  int numCountries = 0;
  for (ObjectVector vector : Collections.list(typeLister.semanticVectors.getAllVectors())) {
    numCountries += typeLister.printBestRelations(vector.getObject().toString());

  }
  System.out.println("Number of countries: " + numCountries);
  //notUsDollar(typeLister, FlagConfig.getFlagConfig(args));
}
 
Example #19
Source File: PrincipalComponents.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Main function gathers search results for a particular query,
 * performs svd, and plots results.
 */
public static void main (String[] args) throws ZeroVectorException {
  // Stage i. Assemble command line options.
  FlagConfig flagConfig = FlagConfig.getFlagConfig(args);
  args = flagConfig.remainingArgs;

  // Get search results, perform clustering, and print out results.
  ObjectVector[] resultsVectors = Search.getSearchResultVectors(flagConfig);
  PrincipalComponents pcs = new PrincipalComponents(resultsVectors);
  pcs.plotVectors();
}
 
Example #20
Source File: ExampleVectorSearcherClient.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Opens vector store from given arg, or if this is empty uses {@link #DEFAULT_VECTOR_FILE}.
 * Then prompts the user for terms to search for.
 *
 * @throws IOException If vector store can't be found.
 */
public static void main(String[] args) throws IOException {
  String vectorStoreName;
  if (args.length == 0) {
    vectorStoreName = DEFAULT_VECTOR_FILE;
  } else {
    vectorStoreName = args[0];
  }

  FlagConfig defaultFlagConfig = FlagConfig.getFlagConfig(null);
  VectorStoreRAM searchVectorStore = VectorStoreRAM.readFromFile(defaultFlagConfig, vectorStoreName);
  LuceneUtils luceneUtils = null;  // Not needed for this simple demo.

  while(true) {
    System.out.println("Enter a query term:");
    Scanner sc = new Scanner(System.in);
    String queryString = sc.nextLine();
    try {
      VectorSearcher searcher = new VectorSearcher.VectorSearcherCosine(
          searchVectorStore, searchVectorStore, luceneUtils, defaultFlagConfig, queryString.split("\\s+"));
      LinkedList<SearchResult> results = searcher.getNearestNeighbors(10);
      for (SearchResult result : results) {
        System.out.println(result.getScore() + ":" + result.getObjectVector().getObject());
      }
    } catch (ZeroVectorException e) {
      System.out.println("No vector for strings: '" + queryString + "'.");
    }
  }
}
 
Example #21
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param queryVecStore Vector store to use for query generation.
 * @param searchVecStore The vector store to search.
 * @param permutationCache The permutations
 * @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
 * @param queryTerms Terms that will be parsed into a query
 * expression. If the string "?" appears, terms best fitting into this position will be returned
 */
public VectorSearcherPerm(VectorStore queryVecStore,
    VectorStore searchVecStore,
    VectorStore permutationCache,
    LuceneUtils luceneUtils,
    FlagConfig flagConfig,
    String[] queryTerms)
        throws IllegalArgumentException, ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);

  try {
    String[] permStrings = queryTerms[1].split(":");
    Vector toSuperpose   = queryVecStore.getVector(queryTerms[0]).copy();
    
    for (String permString:permStrings)
    {
    	theAvg = VectorFactory.createZeroVector(flagConfig.vectortype(), flagConfig.dimension());
        int[] thePermutation = ((PermutationVector) permutationCache.getVector(permString)).getCoordinates();
    	theAvg.superpose(toSuperpose,1, thePermutation);
    	toSuperpose = theAvg.copy();
    }	    
    //int[] thePermutation2 = PermutationUtils.getInversePermutation(thePermutation);
    } catch (IllegalArgumentException e) {
    logger.info("Couldn't create permutation VectorSearcher ...");
    throw e;
  }

  if (theAvg.isZeroVector()) {
    throw new ZeroVectorException("Permutation query vector is zero ... no results.");
  }
}
 
Example #22
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param queryVecStore Vector store to use for query generation.
 * @param searchVecStore The vector store to search.
 * @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
 * @param queryTerms Terms that will be parsed and used to generate a query subspace.
 */
public VectorSearcherSubspaceSim(VectorStore queryVecStore,
    VectorStore searchVecStore,
    LuceneUtils luceneUtils,
    FlagConfig flagConfig,
    String[] queryTerms)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);
  this.disjunctSpace = new ArrayList<Vector>();
  this.vectorType = flagConfig.vectortype();
  
  for (int i = 0; i < queryTerms.length; ++i) {
    System.out.println("\t" + queryTerms[i]);
    // There may be compound disjuncts, e.g., "A NOT B" as a single argument.
    String[] tmpTerms = queryTerms[i].split("\\s");
    Vector tmpVector = CompoundVectorBuilder.getQueryVector(
        queryVecStore, luceneUtils, flagConfig, tmpTerms);
    if (tmpVector != null) {
      this.disjunctSpace.add(tmpVector);
    }
  }
  if (this.disjunctSpace.size() == 0) {
    throw new ZeroVectorException("No nonzero input vectors ... no results.");
  }
  if (!vectorType.equals(VectorType.BINARY))
    VectorUtils.orthogonalizeVectors(this.disjunctSpace);
  else BinaryVectorUtils.orthogonalizeVectors(this.disjunctSpace);
}
 
Example #23
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public VectorSearcherIntersection(VectorStore elementalVecStore, VectorStore semanticVecStore, VectorStore predicateVecStore, 
    VectorStore searchVecStore, LuceneUtils luceneUtils, FlagConfig flagConfig, String term1)
        throws ZeroVectorException {
  super(semanticVecStore, searchVecStore, luceneUtils, flagConfig);
  
 this.intersection=CompoundVectorBuilder.getBoundProductQueryIntersectionFromString(flagConfig, elementalVecStore, semanticVecStore, predicateVecStore, luceneUtils, term1);   
}
 
Example #24
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public VectorSearcherBoundMinimum(VectorStore queryVecStore, VectorStore boundVecStore,
    VectorStore searchVecStore, LuceneUtils luceneUtils, FlagConfig flagConfig, ArrayList<Vector> incomingDisjunctSpace)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);

  this.disjunctSpace = incomingDisjunctSpace;
}
 
Example #25
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public VectorSearcherBoundMinimum(VectorStore queryVecStore, VectorStore boundVecStore,
    VectorStore searchVecStore, LuceneUtils luceneUtils, FlagConfig flagConfig, String term1, String term2)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);

  disjunctSpace = new ArrayList<Vector>();
  Vector queryVector = queryVecStore.getVector(term1).copy();

  if (queryVector.isZeroVector()) {
    throw new ZeroVectorException("Query vector is zero ... no results.");
  }

  this.disjunctSpace = CompoundVectorBuilder.getBoundProductQuerySubSpaceFromString(
      flagConfig, boundVecStore, queryVector, term2);
}
 
Example #26
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public VectorSearcherBoundProductSubSpace(VectorStore queryVecStore, VectorStore boundVecStore,
    VectorStore searchVecStore, LuceneUtils luceneUtils, FlagConfig flagConfig, ArrayList<Vector> incomingDisjunctSpace)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);

  this.disjunctSpace = incomingDisjunctSpace;
}
 
Example #27
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public VectorSearcherBoundProductSubSpace(VectorStore elementalVecStore, VectorStore semanticVecStore, VectorStore predicateVecStore,
    VectorStore searchVecStore, LuceneUtils luceneUtils, FlagConfig flagConfig, String term1)
        throws ZeroVectorException {
  super(semanticVecStore, searchVecStore, luceneUtils, flagConfig);

  disjunctSpace = new ArrayList<Vector>();
  this.disjunctSpace = CompoundVectorBuilder.getBoundProductQuerySubspaceFromString(
      flagConfig, elementalVecStore, semanticVecStore, predicateVecStore, term1);

}
 
Example #28
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public VectorSearcherBoundProductSubSpace(VectorStore queryVecStore, VectorStore boundVecStore,
    VectorStore searchVecStore, LuceneUtils luceneUtils, FlagConfig flagConfig, String term1, String term2)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);

  disjunctSpace = new ArrayList<Vector>();
  Vector queryVector = queryVecStore.getVector(term1).copy();

  if (queryVector.isZeroVector()) {
    throw new ZeroVectorException("Query vector is zero ... no results.");
  }

  this.disjunctSpace = CompoundVectorBuilder.getBoundProductQuerySubSpaceFromString(
      flagConfig, boundVecStore, queryVector, term2);
}
 
Example #29
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param queryVecStore Vector store to use for query generation.
 * @param searchVecStore The vector store to search.
 * @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
 * @param queryVector Vector representing query
 * expression. If the string "NOT" appears, terms after this will be negated.
 */
public VectorSearcherBoundProduct(VectorStore queryVecStore,
    VectorStore searchVecStore,
    LuceneUtils luceneUtils,
    FlagConfig flagConfig,
    Vector queryVector)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);
  this.queryVector = queryVector;
  Vector testVector = searchVecStore.getAllVectors().nextElement().getVector();
  IncompatibleVectorsException.checkVectorsCompatible(queryVector, testVector);
  if (this.queryVector.isZeroVector()) {
    throw new ZeroVectorException("Query vector is zero ... no results.");
  }
}
 
Example #30
Source File: VectorSearcher.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public VectorSearcherBoundProduct(VectorStore elementalVecStore, VectorStore semanticVecStore, VectorStore predicateVecStore,
    VectorStore searchVecStore, LuceneUtils luceneUtils, FlagConfig flagConfig, String term1)
        throws ZeroVectorException {
  super(semanticVecStore, searchVecStore, luceneUtils, flagConfig);

  this.queryVector = CompoundVectorBuilder.getBoundProductQueryVectorFromString(
      flagConfig, elementalVecStore, semanticVecStore, predicateVecStore, luceneUtils, term1);

  if (this.queryVector.isZeroVector()) {
    throw new ZeroVectorException("Query vector is zero ... no results.");
  }
}