Full text
Universidade do Minho Escola de Engenharia Departamento de Informática Martim Bento da Rocha de Almeida Ontology Driven DTD Generation January 2024
Universidade do Minho Escola de Engenharia Departamento de Informática Martim Bento da Rocha de Almeida Ontology Driven DTD Generation Master dissertation Master Degree in Informatics Engineering Dissertation supervised by Professor Pedro Rangel Henriques Professor Maria João Varanda Pereira January 2024
i AUTHOR COPYRIGHTS AND TERMS OF USAGE BY THIRD PARTIES This is an academic work which can be utilized by third parties given that the rules and good practices internationally accepted, regarding author copyrights and related copyrights. Therefore, the present work can be utilized according to the terms provided in the license bellow. If the user needs permission to use the work in conditions not foreseen by the licensing indicated, the user should contact the author, through the RepositóriUM of University of Minho. License provided to the users of this work Attribution-NonCommercial CC BY-NC https://creativecommons.org/licenses/by-nc/4.0/
ii STATEMENT OF INTEGRITY I hereby declare having conducted this academic work with integrity. I confirm that I have not used plagiarism or any form of undue use of information or falsification of results along the process leading to its elaboration. I further declare that I have fully acknowledged the Code of Ethical Conduct of the University of Minho. Martim Bento da Rocha de Almeida
ABSTRACT Ontologies are thought to be excellent representations of a certain domain or body of knowledge, and they are helpful in many different contexts. Using this to its advantage, this document provides a master’s thesis, included in the second year of the Master’s Degree in Informatics Engineering at Universidade do Minho in Braga, Portugal, aimed at developing a tool that transforms an Ontology written in OntoDL (pure or extended) into a DTD file that can serve as a basis for document annotation within the Ontology’s domain of knowledge. This tool, called Onto2DTD, is a web application that allows the user to enter an ontology and get a DTD as an output via an API. In addition, possible conversion errors that may happen in the API are displayed as logs in the application. Thus, in this document, the state of the art for XML schema languages, ontology-based annotation tools, and ontology languages is provided. The proposed approach of the system architecture follows, consisting of a discussion of two possible solutions. Next, the tool’s development is laid out in all of its complexity, including the rules for converting OntoDL to DTD, the design of the API, the structure of the website, and the adjustments made to allow for simultaneous application usage. Together with two operational examples of OntoDL ontologies transformed into DTD using Onto2DTD, the tests conducted during development are also provided. Keywords: Ontology, OntoDL, XML iii
RESUMO As ontologias são consideradas excelentes representações de um determinado domínio ou áreas de conhecimento, sendo úteis em diversos contextos. Aproveitando este facto, este documento apresenta uma tese de mestrado, inserida no segundo ano do Mestrado em Engenharia Informática da Universidade do Minho em Braga, Portugal, que tem como objetivo desenvolver uma ferramenta que transforma uma Ontologia escrita em OntoDL (pura ou estendida) num ficheiro DTD que pode servir de base para a anotação de documentos dentro do domínio de conhecimento da Ontologia. Esta ferramenta, chamada Onto2DTD, é uma aplicação Web que permite ao utilizador introduzir uma ontologia e obter um DTD como resultado através de uma API. Adicionalmentos, os possíveis erros de conversão que possam ocorrer na API são apresentados na forma de logs na aplicação. Assim, neste documento, é apresentado o estado da arte de linguagens XML schema, de ferramentas de anotação baseadas em ontologias e de linguagens de ontologias. Segue-se a abordagem proposta para a arquitetura do sistema, consistindo na discussão de duas soluções possíveis. Em seguida, o desenvolvimento da ferramenta é apresentado em toda a sua complexidade, incluindo as regras de conversão da OntoDL em DTD, a conceção da API, a estrutura do Website e as otimizações efectuadas de forma a permitir a utilização concorrente da aplicação. Juntamente com dois exemplos operacionais de ontologias OntoDL transformadas em DTD através do uso do Onto2DTD, são também apresentados os testes efectuados durante o desenvolvimento. Palavras-Chave: Ontologias, OntoDL, XML iv
CONTENTS 1Introduction 1 1.1Motivation 1 1.2Objectives 1 1.3Research Hypothesis 2 1.4Development Approach 2 1.5Document Structure 2 2State of the Art 3 2.1MnM 3 2.1.1Introduction 3 2.1.2Process Model 5 2.1.3Amilcare 6 2.1.4MnM Conclusion 6 2.2Markup 7 2.2.1Introduction 7 2.2.2Annotation Session 7 2.2.3Active Learning for annotation suggestions 10 2.2.4Markup conclusion 12 2.3Ontology Development 12 2.3.1OWL 12 2.3.2Turtle 14 2.3.3OWL vs Turtle 16 2.3.4OntoDL 16 2.4XML Schema Languages 18 2.5Summary 20 3Proposed Approach 21 3.1Initial Approach 21 3.1.1Parser 22 3.1.2Editor 22 3.2Final Approach 22 3.2.1Parser API 24 3.2.2Frontend 25 3.3Summary 25 4Development 26 v
contents vi 4.1OntoDL to DTD conversion 26 4.1.1OntoDL examination 26 4.1.2DTD definition and rules 27 4.1.3User defined relations 29 4.1.4Default relations 30 4.1.5Attributes 32 4.1.6Header line 32 4.1.7Resulting DTD 32 4.2Parser API 33 4.2.1OntoDL Parser 34 4.2.2DTD Creator 38 4.2.3API Refactoring 39 4.3Website Sketch 40 4.4Frontend 41 4.4.1Website Structuring 41 4.4.2Website Interaction and Parser API access 42 4.5Summary 43 5Testing and Onto2DTD Running Examples 44 5.1Prototype Ontology 44 5.2Pagelas Ontology 46 5.3Summary 49 6Conclusion 51 6.1Future Work 52
LIST OF FIGURES Figure 1MnM 4 Figure 2MnM: Choose an ontology 4 Figure 3MnM: Document annotation 5 Figure 4Markup 7 Figure 5Markup: Annotation session 8 Figure 6Markup: Annotation session setup 8 Figure 7Markup: Config setup 9 Figure 8 Markup: Annotation suggestion process flow diagram (Dobbie et al., 2021)11 Figure 9Proposed Solution 21 Figure 10 Final Solution 24 Figure 11 Tuple nomenclature 29 Figure 12 User defined relation tuple 29 Figure 13 User defined relation DTD result 30 Figure 14 isa relation tuple 30 Figure 15 isa DTD result 30 Figure 16 pof relation tuple 31 Figure 17 pof DTD result 31 Figure 18 syn relation concepts 31 Figure 19 syn relation tuples 31 Figure 20 syn DTD result 32 Figure 21 Attributes DTD result 32 Figure 22 Website sketch 40 Figure 23 Resulting Website Structure 41 Figure 24 Logs modal 42 Figure 25 Prototype Ontology 45 Figure 26 Prototype Ontology resulting DTD 45 Figure 27 Prototype Ontology conversion logs 46 Figure 28 Pagelas Ontology 48 Figure 29 Pagelas Ontology resulting DTD 48 Figure 30 Pagelas Ontology conversion logs 49 vii
2.1. MnM 5 In order to support automatic annotation of documents, MnM makes use of information extraction engines to find different occurrences of concepts related to the chosen ontology in documents. Figure 3: MnM: Document annotation 2.1.2Process Model The process model existent in MnM consisted in five main activities: •Browse: A specific set of knowledge components is chosen from a library of knowledge models on an ontology server. •Mark-up: The chosen set of knowledge components is selected to form the basis of an Information Extraction mechanism. A corpus of documents are manually marked up. •Learning: A learning algorithm is run over the marked up corpus to learn the extraction rules. •Testing: The Information Extraction mechanism is run over a test corpus to assess its precision and recall measures.
2.1. MnM 6 •Extraction: An Information Extraction mechanism is selected and run over a set of documents. As previously mentioned, MnM used information extraction engines to make it possible for documents to be automatically annotated. MnM, however, did not have an integrated tool for information extraction; instead, it had a plug-in interface that permitted the incorporation of information tools. Amilcare was the name of the Information Extract tool that MnM used (Vargas-Vera et al.,2002). 2.1.3Amilcare Amilcare was developed in University of Sheffield and was a tool for adaptive information extraction that supported active annotation of documents, enhancing them with XML annotations. Amilcare was created so that anyone could use it, regardless of their background or level of expertise. Amilcare is based on (LP 2 ), and in order to begin the adaptation process, an ontology is required in order to define a tagset for annotation. After that, users must manually annotate a corpus in order to train the learner. During the annotation made by the users, Amilcare learns how to replicate the various annotation inserted by running the learner in the background. Furthermore, rules are silently being applied to each new text and their results are compared with the user’s annotation. When the rules achieve a user-defined level of accuracy, Amilcare presents each new text with a annotation derived by the rule application where the user has to revise, correct mistakes and add missing annotations. After the corpus annotation process is complete, this system is trained and prepared for use (Ciravegna et al.,2002). 2.1.4MnM Conclusion To summarize, MnM seems to have been a complete application with a lot of features, such as automatic annotation, and customizations. Since the only proofs of existence regarding this application are the user manual and some screenshots (available in this link), it isn’t possible to conclude how easy was to use this application from an user’s point of view.
2.2. Markup 7 2.2 markup 2.2.1Introduction Markup, in Figure 4, is an open-source annotation tool that transforms text documents into structured formats that can be used for Natural Language Processing and Machine Learning tasks, such as named-entity recognition. Markup learns while the user annotates in order to predict and suggest complex annotations. Markup also provides integrated access to existing and custom ontologies, enabling the prediction and suggestion of ontology mappings based on the text that the user is annotating. Markup is available to use as an web application which can be accessed in the following link getmarkup.com. Figure 4: Markup 2.2.2Annotation Session In order to annotate a text document, a Session, as depicted in Figure 5, has to be created where the user has to setup and define certain configurations beforehand.
2.2. Markup 8 Figure 5: Markup: Annotation session As seen in figure 6, these configurations can be required or optional and will be explained further in this section. Figure 6: Markup: Annotation session setup Config To define the entities and attributes that the user wants to annotate, a config file has to be created. This file has to have the .conf extension and must be in the Standoff format. To simplify the process of generating this config file, Markup has a step-by-step setup (Figure 7).
2.2. Markup 9 Figure 7: Markup: Config setup Documents The text documents have to be in the .txt extension and Markup allows uploading multiple text documents to a single session. Existing Annotations These annotations are optional, must have the .ann extension and their names must match the name of the text document related to. Ontology An ontology can be selected or uploaded, and it’s optional, in order to make that terminology available while the user is annotating. The use of ontologies in this tool have the sole purpose of relating the entities and attributes annotated to a domain-specific ontology, whereas in this thesis, the use of ontologies is different since the ontology will be used to define the entities and attributes to annotate. Also, a custom ontology can be uploaded, must have the .txt file extension and must follow this format: 1SOME TERM///SOME CODE ANOTHER TERM///ANOTHER CODE 3. . .
2.2. Markup 10 Smart Assistant Examples In order to the smart assistant to predict and suggest annotations while the user annotates, examples must be uploaded and must have the .txt file format. Unfortunately, the documentation to these examples are quite limited and give no explanation whatsoever. 2.2.3Active Learning for annotation suggestions Despite the fact that annotations have predictable formats, manual annotation takes time. While the user annotates a document , Markup learns to automate the process of identifying, suggesting, and adding complex annotations, with appropriate entities and attributes. Markup achieves this by using active learning and sequence-to-sequence models. The Active Learning model uses a Random Forest classifier to identify target sentences and the wordlevel Long Short-Term Memory based sequence-to-sequence model converts each target sentence into relevant attributes. Based on user interactions with the projected annotation recommendations, the models are continuously modified (Dobbie et al.,2021). The Figure 8 presents this process as a flow diagram for better comprehension.
2.2. Markup 11 Figure 8: Markup: Annotation suggestion process flow diagram (Dobbie et al.,2021)
2.3. Ontology Development 12 2.2.4Markup conclusion To summarize, Markup is a great tool to use to annotate documents while being easy to use and to, for the most part, configure. However, the lack of documentation related to Custom Ontologies and Smart Assistant Examples makes these modules/features unusable for the user. 2.3 ontology development Software can be created using a wide variety of tools, frameworks, and programming languages. The development of ontologies is similar to that. Ontology languages, which are formal languages used to represent ontologies, come in a wide variety and can be either proprietary or standard-based. In this instance, this section will discuss the RDF data model’s OWL and Turtle syntax, both of which are W3C standards, as well as the OntoDL language, which was created at the University of Minho. An example of an ontology related to different types of sports written in each language/syntax will be presented for comparison purposes. 2.3.1OWL The Web Ontology Language OWL is a language for defining ontologies on the Web. An OWL Ontology, with an example in Listing 2.1, describes a domain in terms of classes, properties and individuals and may include rich descriptions of the characteristics of those objects. OWL ontologies can be used to describe the properties of Web resources. Where earlier representation languages have been used to develop tools and ontologies for specific user-communities in areas such as sciences, health and e-commerce, they were not necessarily designed to be compatible with the World Wide Web, or more specifically the Semantic Web, as is the case with OWL (Bechhofer,2009). 1<rdf :RDF xmlns : rdf=" http ://www.w3. org/1999/02/22−rdf −syntax −ns# " 3xmlns : rdfs=" http ://www.w3. org/2000/01/ rdf −schema# " xmlns : owl=" http ://www.w3. org/2002/07/owl# " 5xmlns : dc=" http :// purl . org/dc/elements /1.1/ "> 7<!−− OWL Header Example −−> <owl : Ontology rdf : about=" http ://www. example . org/sports "> 9<dc : t i t l e >Sports example Ontology</dc : t i t l e > <dc : description >A small ontology about sports to serve as an example on how to write an ontology in OWL</dc : description > 11 </owl : Ontology>
2.3. Ontology Development 13 13 <!−− Class and Subclasses −−> 15 <!−− Sport Type Class −−> <owl : Class rdf : about=" http ://www. example . org/sports # sportstype "> 17 <rdfs : label >The Sport Type</rdfs : label > <rd fs : comment>The c l a s s of some sport type </rdf s : comment> 19 </owl : Class > 21 <!−− B a l l Sport Subclass −−> <owl : Class rdf : about=" http ://www. example . org/sports # b al ls po rts "> 23 <rdfs : subClassOf rdf : resource=" http ://www. example . org/sports # sportstype "/> <rdfs : label >Ball Sports </rdfs : label > 25 <rd fs : comment> B al l s po rts are those games th at use a b a l l in play . </ r df s : comment> </owl : Class > 27 <!−− Board Sport Subclass −−> 29 <owl : Class rdf : about=" http ://www. example . org/spor ts # boardsports "> <rdfs : subClassOf rdf : resource=" http ://www. example . org/sports # sportstype "/> 31 <rdfs : label >Board Sports </rdfs : label > <rdfs : comment>These types of sports are played with a s p e c i f i c board used as primary equipment.</ rdfs : comment> 33 </owl : Class > 35 <!−− Racket Sport Subclass −−> <owl : Class rdf : about=" http ://www. example . org/sports # r acket sports "> 37 <rdfs : subClassOf rdf : resource=" http ://www. example . org/sports # sportstype "/> <rdfs : label >Racket Sports </rdfs : label > 39 <rdf s : comment>Racket spo rts encompasses a l l games th at involve h i t t i n g a b a l l or another o b j ect through the use of rackets .</ rdfs : comment> </owl : Class > 41 43 <!−− Individuals −−> 45 <!−− Football −−> <rdf : Description rdf : about=" http ://www. example . org/ spor ts # f o o t b a l l "> 47 <rdf : type rdf : resource=" http ://www. example . org/sports # b a ll s por ts "/> </rdf : Description > 49 <!−− Tennis −−> 51 <rdf : Description rdf : about=" http ://www. example . org/sports # tennis "> <rdf : type rdf : resource=" http ://www. example . org/sports # b a ll s por ts "/> 53 <rdf : type rdf : resource=" http ://www. example . org/sports # r acket sport s "/> </rdf : Description > 55
2.3. Ontology Development 14 <!−− Skateboarding −−> 57 <rdf : Description rdf : about=" http ://www. example . org/sports # skateboarding "> <rdf : type rdf : resource=" http ://www. example . org/sports # boardsports "/> 59 </rdf : Description > 61 </rdf :RDF> Listing 2.1: OWL example As previously mentioned, the ontology defined in Listing 2.1is a representation of several sports. Four classes and three individuals are defined in this ontology. The Ball Sport, Board Sport, and Racket Sport classes are subclasses of the Sports Type class, which is the ontology’s primary class. The individuals defined serve as examples of one or more sports. Football is a type of Ball Sport,Skateboarding is a type of Board Sport and Tennis is a type of Ball Sport and Racket Sport. 2.3.2Turtle The Terse RDF Triple Language, also referred to as Turtle, is a syntax for RDF data expression and is regarded as a standard data format for storing RDF data. RDF represents information using semantic triples, which comprise a subject, predicate, and object. Each item in the triple is expressed as a Web URI. Turtle offers a way to combine three URIs into a triple and ways to condense such information, such as by factoring out common URI components, as can be seen in Listing 2.2. The classes and individuals defined in Listing 2.1are also defined in Listing 2.2. 1@prefix : <http : //www. example . org/sports #> . @prefix owl : <http : //www.w3. org/2002/07/owl#> . 3@prefix rdf : <http : //www.w3. org/1999/02/22−rdf −syntax −ns#> . @prefix xml : <http : //www.w3. org/XML/1998/namespace> . 5@prefix xsd : <http : //www.w3. org/2001/XMLSchema#> . @prefix rdfs : <http : //www.w3. org/2000/01/ rdf −schema#> . 7@base <http : //www. example . org/sports > . 9<http : //www. example . org/sports > rdf : type owl : Ontology ; <http : //purl . org/dc/elements /1.1/description> "A small ontology about sports to serve as an example on how to write an ontology in Turtle " ; 11 <http : //purl . org/dc/elements /1.1/ t i t l e > " Sports example Ontology " . 13 ################################################################# # Annotation properties 15 #################################################################
3 PROPOSED APPROACH With all the state of art and its intricacies researched and acknowledged, the next step to this work is the definition of the system architecture and its features. As discussed earlier, the objectives for this application are: • Help the user write an OntoDL ontology; • Generate a DTD based on the knowledge acquired from the ontology, with the purpose of making annotations in documents that are related to the ontology; • Provide the user with the conversion logs; • Test the DTD’s usability and intregrity through the use of an XML editor; 3.1 initial approach An extensive examination of annotators based on ontologies was conducted, as can be seen in the first and second subsections of the state of the art. The primary cause of it was that the idea of having an XML editor/annotator on the architecture was considered during discussions. Figure 9: Proposed Solution 21
3.2. Final Approach 22 The architecture shown in Figure 9is the outcome of the aforementioned motives. The application can be broken down into two substantial modules, the Parser and Editor, which will each be covered in more detail in the sections that follow. 3.1.1Parser The Parser is composed of 4principal sub modules: • Ontology Checker; • Knowledge Extractor; • DTD Creator; • File Generator; The four sub modules and their capabilities can be explained in a pipeline-like chronological order. The Ontology Checker is a submodule that has the ability to check the syntactic correctness of the user’s OntoDL file before it is accepted as input. After the file has undergone verification, the Knowledge Extractor sub module extracts the pertinent information needed to create the DTD file. In this instance, with OntoDL files, the data from the atributos, conceitos, relacoes and triplos sections are extracted since they provide the data necessary to create the DTD used in the annotations. The information is retrieved and then sent to the DTD Creator submodule, which creates the DTD for the annotations internally. This DTD is displayed in the Editor module and also will pass through the File Generator sub module to create a DTD file that the user may download. 3.1.2Editor The Annotator sub module is the only component of the Editor module. This module will have a built-in text editor with the ability to annotate documents that are received as input. The user must annotate the entire document using this text editor/annotation tool because it only supports manual annotation. Since it falls outside the scope of this work’s research, an automatic annotator/suggestions annotator developed for this application is regarded as future work. 3.2 final approach Additional discussions regarding the project’s goals, the "ecosystem" in which this application will exist and its solution were held prior to beginning the software development.
3.2. Final Approach 23 The primary goal of this project is to create a DTD based on the knowledge obtained from the ontology. The resulting DTD can be used as a starting point for annotating documents that fall under the ontology’s domain. In this instance, the project reads and comprehends ontologies written in OntoDL, a language developed and utilized at University of Minho. In addition to this project, two more initiatives have been created at this university with OntoDL or XML annotation of documents as one of their goals: • WebOntoDL: Available at https://webontodl.epl.di.uminho.pt, a web application that compiles OntoDL into DOT; • WEBXMLIDE: Available at https://webxml.epl.di.uminho.pt, a web application that includes a feature-rich online XML, DTD, XSD, XSLT, and XPath editor. The initial approached in the section before needs to be modified in light of these two Web Apps, which are a part of the same "ecosystem" as this project: • This project should be a web application as the other applications; • Since WEBXMLIDE offers a very approachable and comprehensive XML editor with support for DTD, which is unquestionably ideal for annotating documents, there is no need for developing another XML editor for this purpose; Considering this and going back to the goals stated in section 1.2, it becomes evident that this application does not require the development of an integrated editor because it is possible to perform tasks such as ensuring the usability and integrity of the generated DTD, annotating a document, and then parsing it using a tool that is already a part of the project ecosystem, in this case, WEBXMLIDE.
3.2. Final Approach 24 Figure 10: Final Solution The modifications made considering the discussions resulted in the architecture depicted in Figure 10. The solution can still be divided into two major modules, the Parser API and Frontend, as compared to the previous proposed solution, where the Parser module is now an API and the Frontend module replaces the Editor module. The sections that follow will provide an explanation of both of the new/modified modules. 3.2.1Parser API The Parser API still consists of the same four main sub modules that were included in the earlier proposed solution: • Ontology Checker; • Knowledge Extractor; • DTD Creator; • File Generator; The majority of the sub modules continue to have the functions that were originally described in the initial proposal. The only sub module that had some modifications in its capability was DTD Creator. A DTD file is not internally created in this solution because the Editor module was going to use that feature and this module was modified into the Frontend module. In this situation, the DTD Creator sub module creates and sends the resulting
3.3. Summary 25 DTD to the Frontend along with a few logs of potential events that occurred during the conversion from OntoDL to DTD. 3.2.2Frontend A frontend is required to support the Web Application architecture and enable user interaction with the application. The Frontend for this solution can be split into two parts: • Input, in which a user enters an ontology into the text box or uploads a file containing the ontology that wants to convert; • Output, where the resulting DTD is presented to the user, if the conversion was successful. It is also possible to download the DTD and view the conversion logs. 3.3 summary In the first section of this chapter, the initial approach is presented, where the solution is heavily influenced by the ontology-based annotation tools presented in the State of Art, with the inclusion of an XML editor/annotator in the architecture. However, this approach was discarded due to the existence of an XML editor, WEBXMLIDE, in the same ecosystem as this project. The final approach is a web application, similar to the other tools in its ecosystem. The Editor Module is replaced by a Frontend module, where the user inputs an Ontology and outputs a DTD and some conversion logs. The Parser API module is nearly identical to the Parser module in the initial approach, with the slight difference of being an API.
4 DEVELOPMENT This project’s software development was broken down into four major phases that were finished in the following order: • Establishing rules to convert OntoDL to DTD; • Parser API module development; • Sketching the website structure; • Frontend module development; Each phase will be described in detail, along with every choice taken during its development, in the sections that follow. 4.1 ontodl to dtd conversion Before the Parser API module’s development began, a thorough examination of the OntoDL language was conducted in order to identify the parts of the file’s inherent knowledge that are crucial to the converted DTD file. 4.1.1OntoDL examination As it is present, with a brief explanation in the section 2.3.4, an OntoDL file is composed of the following sections: • Ontologia; • atributos; • conceitos; • individuos; • relacoes; 26
4.1. OntoDL to DTD conversion 27 • triplos; • restricoes; Some elements of an OntoDL ontology may be quite important in defining the various tags present in the DTD, while other sections may be completely unimportant. The construction of the DTD file is most directly related to three primary sections: • conceitos, since this section describes the types of objects/classes included in the ontology; • relacoes, since this section describes how the concepts of the ontology can relate to one another; • triplos, since this part explains how the concepts are related to one another using OntoDL’s declared or default relations. Since the atributos section is optionally defined, it has some significance in the DTD file since these attributes are connected to the concepts in the ontology and will be directly converted into the attributes that a tag can have. Even though it only contains the ontology’s name, the DTD will also make use of the Ontologia section; the following section will further provide more information on why this can be necessary. Lastly, the individuos section does not enter the conversion because the text present in the documents that is going to be annotated have the various individuals that the ontology can have, therefore there is no need to create a specific tag for each individual declared in the ontology. The restricoes section does also not enter the conversion because this is a section that has importance on the ontology but doesn’t bring any important knowledge to the defined of tags or attributes of the DTD. 4.1.2DTD definition and rules Take listing 5.1as an example to translate from OntoDL to DTD using all the information about extracting that has been examined and discussed. As can be seen, this ontology, named Prototype, consists of 7concepts, named ConcA to ConcG, some of which include attributes that were either defined inside the concept itself in the conceitos section or in the atributos section. Three individuals, four relations and twelve tuples, from which the tags that will be constructed in the DTD, are also included in this ontology. Ontologia Prototype 2 atrib u t os { 4AttribA : string ,
4.1. OntoDL to DTD conversion 28 AttribB : string , 6AttribC : int , AttribD : enum (enum1, enum2) , 8AttribE : int } 10 conceitos { 12 ConcA[ AttribA ] , ConcB [ Attrib B ] , 14 ConcC[ AttribC ] , ConcD[ AttribD ] , 16 ConcE [ At tribF : s t r i n g ] , ConcF , 18 ConcG } 20 individuos { 22 InsA , InsB , 24 InsC } 26 relacoes { 28 RelationA , RelationB , 30 RelationC , RelationD 32 } 34 triplos { InsA = i o f => ConcA ; 36 InsA = RelationA => ConcA ; InsB = i o f => ConcB ; 38 InsB = RelationB => ConcB ; InsC = i o f => ConcC ; 40 InsC = RelationC => ConcC ; 42 ConcB = is a => ConcA ; ConcC = pof => ConcB ; 44 ConcD = RelationA => ConcA ; 46 ConcD = RelationB => ConcB ; 48 ConcD = syn => ConcE ; ConcE = syn => ConcF 50 }
4.1. OntoDL to DTD conversion 29 52 restricoes { 54 A = RelationA => B : − B\=InsB , B==InsC ; B\=InsC , B==InsB . } . Listing 4.1: OntoDL Prototype example Figure 11 gives an explanation of the nomenclature of a tuple in order to facilitate the understanding of the rules that make up the resultant DTD file. Figure 11: Tuple nomenclature The three variables subject, predicate, and object make up a tuple. The predicate is a relation, whether it is an OntoDL’s default relation or a relation established by the user, and both the subject and object may only be a concept or an individual. The rule for the definition of a tag in the DTD is derived from the tuple and the relation that is defined in the predicate. In order to clarify the principles that define the resultant DTD tags, let’s divide default relations and user defined relations into their own categories. There is a rule that every element in the DTD must adhere to before delving into detail about the rules for both relations types: • An element is either considered a Mixed Content element or it only contains a #PCDATA. This rule defines that the elements may have zero or more occurrences of #PCDATA or, in case of being a Mixed Content element, may have zero or more occurrences of #PCDATA or any children element the tag may have. 4.1.3User defined relations ConcD = RelationA => ConcA Figure 12: User defined relation tuple This can be understood as "ConcD has relationA with ConcA". In this case, the subject, predicate and object have a defined element, where the subject ConcD has a children element
4.1. OntoDL to DTD conversion 30 that is RelationA and the predicate RelationA has a children element that is the object ConcA. The resulting DTD should be defined as shown below: <!ELEMENT ConcA (#PCDATA)*> <!ELEMENT ConcD (#PCDATA|RelationA)*> <!ELEMENT RelationA (#PCDATA|ConcA)*> Figure 13: User defined relation DTD result 4.1.4Default relations The default relations present in the OntoDL are the following: •isa, which means subclass of; •iof, which means instance of; •pof, which means part of; •syn, which means same as; From these four relations, we can conclude that we can discard any tuple that has iof as a predicate, since it is a relation used normally to associate an individual to a concept. The use of individuals is discarded in the conversion from OntoDL to DTD, therefore there is no need for anything related to the iof relation. To present these three relations that are going to translated into DTD, a tuple from the listing 4.1will be used for each relation. isa relation ConcB = isa => ConcA Figure 14: isa relation tuple This can be understood as "ConcB is a subclass of ConcA", hence the resulting DTD should construct a tag for the object ConcA and the subject ConcB where the object ConcA contains a children element which is the subject ConcB. <!ELEMENT ConcA (#PCDATA|ConcB)*> <!ELEMENT ConcB (#PCDATA)*> Figure 15: isa DTD result
4.2. Parser API 37 115 | ( " i n j e t i v a " | " i n j e c t i v e " ) | ( " inversaDe " | " inverseOf " ) "=" TEXT 117 ISA : " isa " | " is −a " | " subclasse " | " a " | " subClassOf " 119 IOF : " i o f " | " in s ta nc ia " | " instanc eof " | " type " SYN: " syn " | "synonym" | " sinonimo " 121 POF: " pof " | " parte " | " partOf " NOT: " not " | " ! " | "nao " 123 NUM: "−" ? ( " 0" . . " 9" )+ 125 TEXT : ( ( WORD | " ¡ " . . "µ" ) ( "−" | " _ " | "/" | " 0" . . " 9" | WORD | " ¡ " . . "µ" ) *) | ( ( " \" " | " ' " ) /[^ " ']*/ ( "\" " | " ' " ) ) 127 COMMENT: /\s */ "%" /[^\n] /* 129 %import common.WS %import common.WORD 131 %import common . WS_INLINE %ignore WS 133 %ignore COMMENT Listing 4.3: OntoDL+ Lark grammar The implementation of the Parser to start the process of extracting the knowledge from the ontology was initialized once the grammar for OntoDL had been established in Lark and was syntactically correct. There were two classes that could be used to build the Parser using Lark: • Transformer, which operates from the bottom up, visiting the leaves first before automatically moving up the syntax tree until reaching the root; • Interpreter, visits the syntax tree top-down, starting at the root and moving down to the leaves. The Interpreter class does not automatically traverse the sub-branches of the syntax tree, in contrast to Transformer. Because it is possible to have better control over each branch of the syntax tree in this case, the Parser was developed using the Interpreter class. This enables the process of catching any errors that may occur during the parsing of the ontology and generating logs of these errors, which are then provided to the user. To manage the extraction of the ontology and, later, streamline the creation of the DTD, a few variables and data structures were created inside the Interpreter class. The Ontologia, atributos,conceitos,relacoes and triplos sections are those that contain the knowledge used to generate the DTD, as stated in section 4.1.1. There was a variable/data structure made for each of these sections: •Ontologia: A variable that keeps the ontology name;
4.2. Parser API 38 • atributos: An array with each entry consisting of the pair "attribute name" and "attribute type"; • conceitos: A map where the concept name serves as the key and an array of all the concept-related attributes serves as the value; •relacoes: An array containing each defined relation; • triplos: A map with the concept name as the key and another map with the key being a relation related to the concept and the value being an array containing objects related to the concept and relation. In order to store which concepts are synonyms of one another, a new data structure called Syn Pairs was developed. This data structure was necessary because the interpreter extracts knowledge from the ontology line by line, and it was necessary to parse the entire file before performing the process of turning one concept into another in order to create synonym concepts correctly. The handling of potential parsing errors is the only feature still lacking from the Interpreter class, which is ready for knowledge extraction. The errors that the Interpreter can handle result from the file’s correct syntax, which allows the parser to process the entire file without encountering any issues, and its incorrect semantics, which are those errors: • Attribute defined without a type; • Concept used but not defined; • Relation used but not defined; In order to create the DTD without any problems, these errors were fixed by removing them from the ontology. It was necessary to create logs that detailed which attribute, concept, or relationship was incorrectly or not at all defined in order for the user to understand that these errors occurred. A log that alerts the user that one concept is a synonym for another is also created in addition to these three logs because one concept will have all of its relations and attributes removed and copied from another. 4.2.2DTD Creator The process of developing the module that converts the knowledge into DTD started once all the rules for DTD elements and attributes were already established and the knowledge had been obtained retrieved from the OntoDL Parser. Due to the work done previously on the OntoDL Parser, the construction of the two submodules DTD Creator and File Generator for the DTD Creator module was straightforward.
4.2. Parser API 39 The File Generator is a very simple sub-module because it simply needs to transform the DTD to create the file. The knowledge retrieved from the triplos section, which represents all relationships between concepts in the ontology, as well as from the atributos section, since a concept that is the subject or object of a tuple may have attributes related to it, is provided to the DTD Creator in order to create the DTD elements and attributes correctly. The following steps must be taken in the correct order to build the DTD file: • Create DTD elements of concepts that are subjects of some tuple; • Create DTD elements of the user defined relations; • Create DTD elements of concepts that are only objects of some tuple; • Create DTD attributes that are related to the Elements of the DTD; • Create DTD element for the header line. Following this process of construction, the finished DTD file is going to be ready to be used to annotate any documents since any errors have been properly resolved by the OntoDL Parser. 4.2.3API Refactoring The creation of the API class is the final step in finishing the Parser API module. As previously said, the Flask library was utilized to construct the API because it is a fairly straightforward web framework library to work with. Three routes were built for the API: • "/", called when the conversion from OntoDL to DTD is wanted. This route receives the ontology and checks to see if knowledge can be extracted from it. If possible, the conversion is performed and returned to the user; otherwise, a "Ontology Error" error is returned; •"/logs", called to deliver the conversion logs; • "/download", called to deliver the DTD as well as the Ontology name in order to build the file in the frontend; It was required to utilize a unique request header called user-id and to create a User Datastore in order to allow for concurrent users to use the API without overwriting each other’s results. A map with the user-id from the header as the key and a tuple with the ontology, the resultant DTD, the ontology name, and the logs as the value make up this datastore.
4.3. Website Sketch 40 4.3 website sketch A website structure sketch had to be created before the Frontend module could be developed in order to facilitate module development. The website will be a single-page web application since it will contain an application to transform the ontology into a DTD. The main goal of the frontend is simplicity, which will improve the user’s experience with this application. Figure 22: Website sketch The website sketch is shown in figure 22. The website is made up of a Header and a Footer, obviously, as well as a center section where the user can convert an ontology into a DTD. There are two subsections in this center section: • Input, where the user can click a button to upload a file that automatically fills a textarea with the ontology or manually enter the ontology into a textarea; • Output, if the ontology is written successfully, the user receives the DTD inside a textarea along with a button to download the DTD file and a button to access a modal that contains the conversion logs.
4.4. Frontend 41 4.4 frontend The creation of the Frontend module was split into two stages, with the Parser API routes and figure 22 serving as the basis: • Website Structuring; • Website Interaction and Parser API access. Selecting programming languages, frameworks, and libraries for this module was easy to accomplish. Javascript was the ideal option for programming language because this subject is about developing a single-page application. Express was selected as the web framework for this module because it is lightweight and fast, allowing a quick building of SPA. For improvements in the visual appearance of the SPA, Tailwind CSS was utilized as the CSS framework. Lastly, the Axios library was utilized to enable the website to perform calls to the Parser API. 4.4.1Website Structuring The primary goal for the website’s development was to precisely duplicate the design shown in the sketch displayed in figure 22, and then change its visual appeal by utilizing Tailwind and CSS. The goal described above led to the creation of the website structure that can be seen in figure 23. Figure 23: Resulting Website Structure
4.4. Frontend 42 The creation of a modal, or popup window, that displays the logs of the conversion from OntoDL to DTD, displayed in figure 24, was an additional feature added to the website that was not included in the sketch. Figure 24: Logs modal 4.4.2Website Interaction and Parser API access A certain level of interactivity is available on the website and can be found on the buttons, as presented in section 4.3: • Upload File: this will cause a file to be opened and its contents to show up in the Input Textarea; • Download File: which saves the generated DTD from the Output Textarea as a file with the Ontology name as its’ name; • View Logs: this will open the modal that has the logs in it, as referenced in figure 24; • Convert: which transmits the contents of the Input Textarea to the API and displays the outcome in the Output Textarea thereafter. The website accesses the Parser API via the following routes: •"/convert", delivering the resulting DTD from the API after the Ontology is sent; • "/download", obtaining the most recent DTD produced by the user’s most recent conversion;
4.5. Summary 43 •"/logs", obtaining the user’s most recent conversion logs. The website generates a cookie that is subsequently transmitted in all of these routes, which contains the user-id request header that the API uses for concurrent user usage. 4.5 summary The project was developed in four stages: OntoDL to DTD conversion, during which the conversion rules were defined and discussed; Parser API development, in which the languages and libraries, as well as the OntoDL Parser and DTD Creator Classes, were explained in detail; Website Sketch, where the frontend module development was made easier by the creation and discussion of the website sketch for the frontend module; Frontend module development, where the framework and programming language selections were justified along with explanations for the website’s structuring and interactivity, and access to the Parser API via the website.
5 TESTING AND ONTO2DTD RUNNING EXAMPLES Numerous tests were conducted during the project’s development to ensure that each stage of implementation was carried out successfully. These tests included the following: • Checking the grammar validity; • Parsing OntoDL files; • Transforming OntoDL files into DTD; • Checking the connection between the API routes. • Checking the connection between the Frontend and the API; A great approach to illustrate all of these tests is to provide some working examples, in this case, two ontologies: the Pagelas ontology, which is the first ontology defined with OntoDL, and the ontology shown in Listing 4.1, where the expected result for the DTD should resemble the result shown in Listing 4.2. It is achievable to run OntoDL defined files in both variants, avoiding the need to update already-defined OntoDL ontologies into OntoDL+, as demonstrated by converting these ontologies into DTD using this project. The live version of Onto2DTD, or the version hosted at https://ontodtd.epl.di.uminho.pt, was utilized to obtain the result to these examples. 5.1 prototype ontology Ontology as stated in Listing 4.1is displayed in the frontend input field, as shown on the left of Figure 25. Figure 26 displays the ontology conversion outcome on the right. The resulting DTD can be determined to be the same by comparing the result with the predicted result shown in Listing 4.2. Since the definition of an element and attribute in a DTD file is more significant than its line or order, some DTD elements and attributes may be displayed in a different order, which does not indicate any error or problem at all. 44
5.1. Prototype Ontology 45 Figure 25: Prototype Ontology Figure 26: Prototype Ontology resulting DTD Lastly, Figure 27 displays the conversion logs. From this, we can observe that the ontology’s individuals have been removed and that concepts with synonym relations share the same properties and relations—a behavior that is regarded as desirable and is discussed in section 4.1.2.
5.2. Pagelas Ontology 46 Figure 27: Prototype Ontology conversion logs 1Sub jec t InsA used but not defined , sub je ct i s omitted Sub jec t InsB used but not defined , s ub je ct i s omitted 3Sub jec t InsC used but not defined , su bj ec t i s omitted Concept "ConcE" i s synonym of "ConcD" , " ConcE " a t t r i b u t e s and r e l a t i o n s w il l be removed and copied from "ConcD" 5Concept " ConcF " i s synonym of "ConcE" , " ConcF " a t t r i b u t e s and r e l a t i o n s w il l be removed and copied from "ConcE" Listing 5.1: Prototype Ontology conversion logs 5.2 pagelas ontology Listing 5.2is an overview of the Pagelas ontology. The omission of the atributos and restricoes sections, which are regarded as optional due to the fact they were introduced in the OntoDL+ version, is an easy way to understand why this ontology is defined in OntoDL and not OntoDL+. 1Ontologia Pagelas 3conceitos { Pagela [ tipo : string , imagem_frente : string , imagem_tras : string , conteudo : st ri ng ] , Pessoa [nome : s t r in g ] , 5Santo [nome : s tri ng , h i s t o r i a : s t ri ng ] , Evento [ data : str in g , l o c a l : s t ri n g ] , 7Festa_Religiosa , Batizado ,
BIBLIOGRAPHY Andreas Abecker and Ludger van Elst. Ontologies for Knowledge Management, pages 713–734. 05 2009. doi: 10.1007/978-3-540-92673-3_32. Sean Bechhofer. OWL: Web Ontology Language, pages 2008–2009. Springer US, Boston, MA, 2009. ISBN 978-0-387-39940-9. doi: 10.1007/978-0-387-39940-9_1073. URL https: //doi.org/10.1007/978-0-387-39940-9_1073. Geert Jan Bex, Frank Neven, and Jan Van den Bussche. Dtds versus xml schema: A practical study. In Proceedings of the 7th International Workshop on the Web and Databases: Colocated with ACM SIGMOD/PODS 2004, WebDB ’04, page 79–84, New York, NY, USA, 2004. Association for Computing Machinery. ISBN 9781450377881. doi: https: //doi.org/10.1145/1017074.1017095. Fabio Ciravegna, Alexiei Dingli, Yorick Wilks, and Daniela Petrelli. Amilcare: adaptive information extraction for document annotation. In Proceedings of the 25th annual international ACM SIGIR conference on Research and development in information retrieval, pages 367–368,2002. Oscar Corcho. Ontology based document annotation: Trends and open research problems. International Journal of Metadata, Semantics and Ontologies,1(1):47–57,2006. Ontology Engineering Group ? OEG. Samuel Dobbie, Huw Strafford, W Owen Pickrell, Beata Fonferko-Shadrach, Carys Jones, Ashley Akbari, Simon Thompson, and Arron Lacey. Markup: A web-based annotation tool powered by active learning. Front Digit Health,3:598916, July 2021. Michael Erdmann and Rudi Studer. Ontologies as conceptual models for xml documents. 1999. URL https://api.semanticscholar.org/CorpusID:15619375. Henrik Eriksson. An annotation tool for semantic documents. In Enrico Franconi, Michael Kifer, and Wolfgang May, editors, The Semantic Web: Research and Applications, pages 759–768, Berlin, Heidelberg, 2007. Springer Berlin Heidelberg. ISBN 978-3-540-72667-8. Jun Fang, Lei Guo, XiaoDong Wang, and Ning Yang. Ontology-based automatic classification and ranking for web documents. In Fourth International Conference on Fuzzy Systems and Knowledge Discovery (FSKD 2007), volume 3, pages 627–631,2007. doi: 10.1109/FSKD. 2007.432. 53
BIBLIOGRAPHY 54 Andrew Frank. Tiers of ontology and consistency constraints in geographical information systems. International Journal of Geographical Information Science,157667-678,01 1998. Thomas R. Gruber. A translation approach to portable ontology specifications. Knowledge Acquisition,5(2):199–220,1993. ISSN 1042-8143. doi: https://doi.org/10.1006/knac.1993. 1008. David Gulbransen. Special Edition Using Xml Schema. Que Corp., USA, 2001. ISBN 0789726076. Maria João Varanda Pereira, João Fonseca, and Pedro Rangel Henriques. Ontological approach for dsl development. Computer Languages, Systems & Structures,45:35–52,2016. ISSN 1477-8424. doi: https://doi.org/10.1016/j.cl.2015.12.004. Mu-Hee Song, Soo-Yeon Lim, Dong-Jin Kang, and Sang-Jo Lee. Automatic classification of web pages based on the concept of domain ontology. In 12th Asia-Pacific Software Engineering Conference (APSEC’05),2005. doi: 10.1109/APSEC.2005.46. S. Staab and R. Studer. Handbook on Ontologies. International Handbooks on Information Systems. Springer Berlin Heidelberg, 2009. ISBN 9783540926733. doi: https://doi.org/ 10.1007/978-3-540-92673-3. Mark Stevenson and Yikun Guo. Disambiguation of ambiguous biomedical terms using examples generated from the umls metathesaurus. Journal of Biomedical Informatics,43 (5):762–773,2010. ISSN 1532-0464. doi: https://doi.org/10.1016/j.jbi.2010.06.001. Maria Vargas-Vera, Enrico Motta, John Domingue, Mattia Lanzoni, Arthur Stutt, and Fabio Ciravegna. Mnm: Ontology-driven tool for semantic markup. In SAAKM@ ECAI,2002.