Program Graph Indexing for Source Code Snippet Search

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing software repositories contain incomplete source code snippets that cannot be compiled or analyzed by conventional analysis software, limiting users' ability to find relevant programming solutions through simple text searches.

Innovation Solution

A method is introduced to index and access code snippets by creating a program graph index that reflects the semantics, structure, and syntax of code snippets, allowing users to provide a target code snippet and identify matching documents with similar program graphs, thereby presenting relevant source code snippets.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Ease of operation

If source code snippets are stored as plain text in repositories, then users can perform simple text searches, but the search effectiveness is limited and cannot analyze code structure or semantics

Engineering Contradiction:
Improvesearch simplicityVSAvoidsearch accuracy
Core Design Contradiction:
Ease of operationVSMeasurement precision

Solution Approach 1:

The patent transforms code snippets from plain text format into structured program graphs with multiple parameters (nodes representing code elements, edges representing relationships). This parameter change enables the system to analyze code structure, semantics, and syntax while maintaining search functionality, thereby improving search accuracy without completely sacrificing ease of operation.

Inventive Principle:
Principle #35Parameter changes

Solution Approach 2:

The patent introduces program graphs as an intermediary representation between plain text code snippets and search queries. These graphs serve as a mediator that captures both the textual content and structural relationships of code, enabling more accurate semantic search while building upon the simple text search foundation.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Quantity of substance

If incomplete source code snippets are stored in repositories, then repository size is reduced, but the snippets cannot be compiled or analyzed by conventional analysis software

Engineering Contradiction:
Improverepository sizeVSAvoidcode completeness
Core Design Contradiction:
Quantity of substanceVSReliability

Solution Approach 1:

The patent changes the representation parameters of code snippets from complete compilable code to structured program graphs that capture essential code elements and relationships. This transformation allows the system to work with incomplete snippets effectively by focusing on the structural and semantic relationships rather than requiring complete compilable code, thus maintaining reliability for search purposes while keeping repository size manageable.

Inventive Principle:
Principle #35Parameter changes

3Speed

If conventional text search is used on code repositories, then search speed is fast, but the ability to find semantically relevant code is limited

Engineering Contradiction:
Improvesearch speedVSAvoidsemantic information
Core Design Contradiction:
SpeedVSLoss of information

Solution Approach 1:

The patent segments code into structured program graph components (nodes and edges representing different code elements and their relationships). This segmentation allows the search system to process and compare specific code elements and their relationships efficiently, maintaining search speed while preserving and utilizing semantic information that would be lost in plain text search.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The patent adds a structural dimension to code representation by creating program graphs with nodes and edges. This dimensional transformation from one-dimensional text to two-dimensional graph structure enables the system to capture and search for semantic relationships while maintaining efficient search capabilities through graph-based indexing and comparison.

Inventive Principle:
Principle #17Another dimension (Dimensionality change)

Data Source

PatentUS20220374212A1Indexing and accessing source code snippets contained in documents
Publication Date: 2022.11.24 INTERNATIONAL BUSINESS MACHINE CORPORATION
  • US20220374212A1 patent drawing
  • US20220374212A1 patent drawing
  • US20220374212A1 patent drawing

AI summary

Systems and methods for indexing and accessing code snippets in repositories. A program graph index is maintained for code snippets within a repository with documents that have at least one code snippet. The program graph index includes a program graph indicating a relationship between program elements within each source code snippet within the documents. A user provided code snippet is received and a target program graph indicating a relationship between program elements within the user provided code snippet is determined and compared to each respective program graph. Based on the comparison, an identified set of documents within the repository of documents is determined that have code snippets with respective program graphs that are also at least a sub-tree of the target program graph. At least one document in the identified set of documents is presented to a user.