IP Library Granted Patent US 12681703
Granted Patent B1
US 12681703 · App. 18/531,352 · Granted Jul 14, 2026

Semantic matching of search queries against a target code

Inventors: Pranav Garg (Secaucus, NJ); Yanjun Wang (Santa Clara, CA); Benjamin Robert Liblit (Leesburg, VA); Omer Tripp (San Jose, CA)
Assignee: Amazon Technologies, Inc.
G06F8/42
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12681703
App. No.
18/531,352
Granted
Jul 14, 2026
Kind
B1
Abstract

A search language is provided for writing rules that allow semantic and syntactic checking of source code to find potential errors in a target code. The language allows for wildcards (also called placeholders), which provide a more expansive matching of search terms. A compiler is described that converts a search language query into a semantic graph representation. The target code being searched can also be converted to a target graph representation. A comparison can then be performed between the semantic graph representation and the target graph representation to determine if the semantic graph representation is contained within the target graph representation. If so, then a semantic match is found in the target source code. More specifically, semantic matching can be realized by checking homomorphism against the target graph representation. In one example, the semantic matching can include a comparison of nodes and edges connecting the nodes.

Claims (32)

1 . A method of performing semantic analysis on source code, the method comprising:

receiving a search language query including syntactic variations using at least one wildcard value and a data type constraint;

converting the search language query into a semantic graph representation including at least two nodes and one or more edges between the nodes;

converting the source code into a target graph representation including nodes and edges between the nodes; and

mapping the semantic graph representation to the target graph representation and determining that there is a match if the semantical graph representation is contained within the target graph representation;

wherein the converting the search language query into the semantic graph representation and the converting of the source code into the target graph representation occurs within a compiler and wherein the compiler further includes a front end that validates a syntax of the search language query.

2 . The method of claim 1 , wherein the mapping includes using a homomorphism by mapping elements in the semantic graph representation to elements in the target graph representation.

3 . The method of claim 1 , wherein the wildcard is a character that can be interpreted as any number of literal characters.

4 . The method of claim 1 , wherein the mapping includes ensuring that the edges between the nodes match between the semantic graph representation and the target graph representation.

5 . A computer system comprising a processing system and memory, wherein the computer system is configured to perform operations, comprising:

receiving a semantic search language instruction, wherein the instruction includes a search language code portion specifying, semantically, source code to be matched, and a constraint portion that further limits the search language code portion;

receiving the source code to be searched;

converting the semantic search language instruction to a semantic graph representation;

converting the source code to a target graph representation; and

mapping the semantic graph representation to the target graph representation to find a match of the semantic search language instruction;

wherein the operations are performed within a compiler executing in the computer system and wherein the compiler includes a front end that validates a syntax of the semantic search language instruction.

6 . The computer system of claim 5 , wherein the code portion includes a wildcard value in the code to be matched so that syntactic variations of the code are matched.

7 . The computer system of claim 5 , wherein the mapping of the semantic graph representation to the target graph representation includes using homomorphism by mapping elements in the semantic graph representation to elements in the target graph representation.

8 . The computer system of claim 5 , wherein the constraint portion includes a data type constraint that the target graph representation includes to have a match.

9 . The computer system of claim 5 , wherein the constraint portion includes a data flow constraint or a literal value constraint that the target graph representation includes to have a match.

10 . The computer system of claim 5 , wherein the operations further include outputting a results of the mapping to a debugger that presents information about matches and non-matches that were determined.

11 . The computer system of claim 5 , wherein the semantic graph representation and the target graph representation include nodes and edges between the nodes and wherein the mapping includes matching the nodes and the edges.

12 . A method, comprising:

receiving a semantic search language instruction having a search language code portion including a programming instruction to search on, wherein the search language code portion includes at least one wildcard that is a parameter of the programming instruction or within the programming instruction, wherein the semantic search language instruction includes a constraint;

receiving a target source code to be searched; and

matching the semantic search language to the target source code using a homomorphism,

wherein the receiving of the target source code and the matching of the semantic search language to the target source code occur within a compiler and wherein the compiler validates a syntax of the search language instruction.

13 . The method of claim 12 , wherein the matching includes mapping elements in a semantic graph representation to elements in a target graph representation.

14 . The method of claim 12 , wherein the matching includes converting the semantic search language instruction into a semantic graph representation and converting the target source code into a target graph representation and then determining whether the semantic search language instruction is contained within the target graph representation.

15 . The method of claim 14 , wherein the semantic graph representation and the target graph representation include nodes and edges and the matching includes comparing the nodes and edges of the semantic graph representation to the nodes and edges of the target graph representation.

16 . The method of claim 12 , wherein the wildcard allows syntactic variations in the target source code to match the semantic search language instruction.

17 . The method of claim 12 , wherein the constraint is a data type and the data type further limits the code portion.