Query-by-example code search using syntax trees

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Conventional code search tools are primarily text-based and struggle to effectively discover syntactic patterns in source code, limiting their ability to identify relevant code samples for software developers performing tasks like refactoring or learning about programming interfaces.

Innovation Solution

A query-by-example system that generates syntax structures and characteristic vectors from query snippets, allowing for the comparison and retrieval of source code files based on syntactic similarities, using Abstract Syntax Trees (ASTs) and tree similarity algorithms to identify relevant code files.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Adaptability or versatility

If text-based search tools are used for code search, then implementation simplicity is maintained, but the ability to discover syntactic patterns is insufficient

Engineering Contradiction:
Improveability to discover syntactic patternsVSAvoidsearch system complexity
Core Design Contradiction:
Adaptability or versatilityVSDevice complexity

Solution Approach 1:

The patent introduces syntax trees as an intermediary representation between raw source code and search queries. The query module converts both the query snippet and source code files into syntax trees, enabling structural pattern matching without requiring complex direct analysis of source code. This intermediary representation simplifies the comparison process while enhancing syntactic pattern discovery capabilities.

Inventive Principle:
Principle #24Intermediary (Mediator)

Solution Approach 2:

The patent replaces traditional text-based mechanical search operations with a semantic comparison mechanism based on syntax tree structures. Instead of simple string matching, the system uses tree structure comparison algorithms that understand programming language syntax, enabling more intelligent pattern recognition while maintaining computational efficiency through structured data representation.

Inventive Principle:
Principle #28Mechanics substitution (Replace mechanical system)

2Measurement precision

If conventional text-based search is used, then search speed is maintained, but search accuracy for syntactic patterns is insufficient

Engineering Contradiction:
Improvesearch accuracyVSAvoidsearch time
Core Design Contradiction:
Measurement precisionVSLoss of time

Solution Approach 1:

The patent performs preliminary conversion of source code files into syntax trees and stores them in a database before search operations. This pre-processing step enables rapid retrieval during actual search operations, as the system only needs to convert query snippets and compare against pre-processed syntax trees, significantly reducing search time while maintaining high accuracy.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent creates simplified copies of source code in the form of syntax trees that capture essential structural information while omitting irrelevant details. These syntax tree copies enable efficient comparison operations, as the system compares structural representations rather than full source code texts, improving both accuracy and speed.

Inventive Principle:
Principle #26Copying

Data Source

PatentUS9317260B2Query-by-example in large-scale code repositories
Publication Date: 2016.04.19 VMWARE INC
  • US9317260B2 patent drawing
  • US9317260B2 patent drawing
  • US9317260B2 patent drawing

AI summary

Systems and methods for performing query-by-example are described. A query module executing on the system may maintain a source code repository containing a plurality of source code files. Each of the plurality of source code files is associated with a corresponding source syntax structure generated based on said each of the plurality of source code files. The query module may receive a query snippet, and generate a query syntax structure based on the query snippet. The query module may then identify a first source code file from the plurality of source code files for being relevant to the query snippet. The being relevant to the query snippet is determined by a first relevance score which is calculated based on the query syntax structure and the first source code file's corresponding source syntax structure.