Introduction
Modern software development relies heavily on the reuse of open-source components. However, navigating and searching these vast repositories remains a challenge. Traditional tools often rely on keyword-based text searches or rigid graph models that lack extensibility. CodeOntology addresses this by bridging the gap between software engineering and the Semantic Web, transforming Java source code into a queryable RDF format. By mapping code structures to an OWL 2 ontology and linking documentation to external knowledge bases like DBpedia, it enables "concept-aware" searches that go beyond simple string matching.
Methodology
The CodeOntology framework consists of two core components: a formal OWL 2 ontology and a specialized parser.
OWL 2 Ontology
The ontology provides a formal model for object-oriented programming constructs. It defines classes, methods, variables, and their hierarchical relationships, allowing software to be represented as a structured knowledge graph.
Extraction and Semantic Enrichment
The extraction process uses a parser built on the Spoon library to analyze Java source code or bytecode. This tool serializes the code structure into RDF triples. A key innovation is the integration of TagMe, a named entity disambiguation tool. TagMe scans source code comments to identify mentions of real-world entities and links them to DBpedia. For instance, a comment describing "AES encryption" is linked to the corresponding DBpedia resource, enabling semantic retrieval based on high-level concepts rather than just identifier names.
Dataset and Composition
To evaluate the framework, the authors processed the OpenJDK 8 source code, generating a dataset of approximately 2 million RDF triples.
As shown in the figure above, the dataset is primarily composed of structural information (78.26%), which includes class hierarchies and method signatures. DBpedia links account for 12.23% of the triples, while source code literals and comments make up the remaining 9.5%. This distribution underscores the framework's focus on capturing the architectural and semantic context of the software.
Applications and Results
By treating code as a knowledge graph, CodeOntology enables complex analysis through standard SPARQL queries.
- Structural and Dependency Analysis: Queries can easily identify recursive methods or track class dependencies. In OpenJDK 8,
java.lang.Stringwas identified as the most referenced class. - Semantic Search: The framework excels at finding functionality based on intent. A query for resources associated with
dbpedia:Cube_rootsuccessfully identified thecbrt(double)methods injava.lang.Mathandjava.lang.StrictMath, even without explicit keyword matches in the method names. - Pattern and Metric Detection: The RDF graph supports the detection of design patterns (e.g., Singleton, Factory) and the computation of software metrics (e.g., CK metrics) by analyzing the relationships between entities.
Conclusion
CodeOntology demonstrates the power of applying Semantic Web technologies to software analysis. By standardizing code representation using OWL 2 and SPARQL, it ensures interoperability with existing knowledge bases and tools. Future work aims to expand language support beyond Java and delve into finer-grained analysis of method bodies to further enhance automated design pattern detection and software metric computation.
Summary updated