Due to factors such as suboptimal construction quality and severe environmental disasters, a range of dangerous situations, including landslides, cracks, and flooding, may arise during the operational and maintenance stages of earth—rock dams. At present, a large amount of data related to dangers of earth and rock dam is dispersed and exists in diverse forms, posing challenges for its conversion into experiential knowledge for efficient utilization and swift guidance in hazard mitigation. Consequently, a knowledge graph (KG) construction method is proposed in this study, integrating ontology and Natural Language Processing (NLP). To construct pattern and data layers of the graph, this method employs the top—down and bottom—up methods, respectively. The pattern layer centers on three primary concepts; risk types, risk causes, and risk disposal measures. A domain ontology library is established encompassing four facets of earth-rock dam structure, process, environment, and materials, and a conceptual framework of KG is built. The construction of the data layer encompasses operations such as data preprocessing, knowledge extraction, and semantic alignment. NLP is employed to process the text and formulate extraction rules based on corpus characteristics, facilitating the acquisition of specific knowledge content for the data layer. Ultimately, various types of instances and their relationships are stored in the form of triplets. The Neo4j platform is employed to actualize the visual representation and querying application of the KG within the dangers of earth-rock dam. This transformation of dispersed data in the domain into integrated knowledge offers essential technical and theoretical support for the safety management and hazard mitigation of earth-rock dams. © 2024 International Research and Training Center on Erosion and Sedimentation and China Water and Power Press. All rights reserved.