The technical capabilities of modern Industry 4.0 and Industry 5.0 are rather vast and growing exponentially daily. The present-day Industrial Internet of Things (IIoT) combines manifold underlying technologies that require real-time interconnections and communications among heterogeneous devices. Smart cities are established with sophisticated designs and control for seamless Machine-to-Machine (M2M) communication to optimize resources, costs, performances, and energy distribution. All the sensory devices within a building interact to maintain a sustainable climate for residents and intuitively optimize the energy distribution to optimize energy production. However, it encompasses quite a few challenges for devices that lack compatible and interoperable designs. Conventional solutions are restricted to limited domains or rely on engineers to design and deploy translators for each pair of ontologies. This is a costly process in terms of engineering efforts and computational resources. The issue persists that a new device with a different ontology must be integrated into an existing IoT network. We propose a self-learning model that can determine the taxonomy of devices given their ontology meta-data and structural information. The model finds matches between two distinct ontologies using the Natural Language Processing (NLP) approach for learning linguistic contexts. Then, by visualizing the ontology network as a knowledge graph, it is possible to learn the structure of the meta-data and understand the device's message formulation. Finally, it can align entities of both ontology graphs similar in context and structure. Furthermore, the model performs dynamic M2M translation without requiring extra engineering or hardware efforts.