Starting from:

$30

COMP249-Assignment 3 Bib Creator Solved

The purpose of this assignment is to allow you practice Exception Handling, and File I/O, as well as other previous object-oriented concepts.  

 JavaScript Object Notation or JSON is a well-known, lightweight data-interchange format, which is easily readable/writable by humans [1][2]. It is also easy for machines to parse and generate. JSON is based on data objects consisting of attribute–value pairs and array data types. It is widely used for asynchronous browser–server communication, including as a replacement for XML in some AJAX-style systems. As such,  many journals and scientific servers are supporting this format. This format is easily extendable. The following is a typical sample (modified from an existing IEEE paper).
 

In JSON, the fields however do not need to be placed in specific order. For example, in the above example, you can have the “number” filed for instance, be written above the “year” field, and so on.  

 

There are many parsers available for JSON developed in may programming language as library, API, etc. Mendeley [3] is one example that uses this format. With Mendeley you can create your own library from all articles that you have read so far and you can use them when you want to write an article. Consequently, this is very good for inserting the needed references on a published paper and managing them afterwards. In particular, such tools can import the article(s) information from a bibliography file (.bib) and generate the reference(s) in particular format according to the conference or journal publisher standard.  

 

For example, the representation of this file in IEEE format would be (this is a slightly simplified version than the actual one; however you need to follow this format for the scope of this assignment):  

J. Park, J. N. James, Q. Li, Y. Xu, W. Huang. "Optimal DASH-Multicasting over LTE", IEEE Transactions on Vehicular Technology, vol. PP, no. 99, p. 15-27, January 2018. 

 

Or in ACM format would be:  

 

[1] J. Park et al. 2018. Optimal DASH-Multicasting over LTE. IEEE Transactions on Vehicular Technology. PP, 99 (2018), 15-27. DOI:https://doi.org/10.1109/TVT.2018.2789899. 

 

And finally, in Nature Journal (NJ), which is one of the most famous journals in natural science, would be  

J. Park & J. N. James & Q. Li & Y. Xu & W. Huang. Optimal DASH-Multicasting over LTE. IEEE Transactions on Vehicular Technology. PP, 15-27(2018). 

 

You should have a “very” detailed look at these formats to see how they are mapped from the original record of the article.  

 

In this assignment, you will be designing and implementing an alternative tool (to the existing ones), called BibliographyFactory. The main task of this tool is read and process a given .bib file (which has one or more articles) and create 3 different files with the correct reference formats for IEEE, ACM and NJ.  

 

In short, you are given 10 files, called Latex1.bib to Latex10.bib. You BibliographyFactory application will need to read all 10 input files (in one execution), determine whether each of these files is valid or not (details given below). If a file is valid, then BibliographyFactory will create 3 different files based on the articles in this file, one for IEEE format, one for ACM format and the last for NJ format. To distinguish our application from other existing similar software, we will call these files IEEEi.json, ACMi.json, and NJi.json (although in fact, the created files contain the references to the articles, and not json records!), where i is the Latex file #. For instance, Latex3.bib will result in the creation of 3 files called: IEEE3.json, ACM3.json and NJ3.json. If a file is invalid, then none of the 3 output reference files (for this invalid file) is created. So, in best case, BibliographyFactory execution will result in the creation of 30 output files if all given Latex files are valid, and in worst case it will create 0 files (when all 10 input files are invalid).  

 

The fine details of what you need to do and how your BibliographyFactory should work are given below.  

 

1.      For the purpose of this assignment, and to provide little simplifications, the following should be assumed in relation to the input files and the articles (records) in these input file:

a.      Each file may have one or more articles; the number is unknown before processing, and your code must assume that;

b.      An article starts with @ARTICLE followed by the body of the article (between “{“ and

“}”). It is assumed that all articles have enclosing bodies;

c.      Inside each of these articles, there exists few fields; i.e. author, volume, year, etc. These fields are assumed to always start with the field name, followed by an “=” sign and a “{“ character. For instance: pages={ , month=  , etc.  

d.      It also assumed that each of the bodies of these fields have a closing character for its body. In specific, it is assumed that each of these fields end with “},”;

e.      For simplicity, it is also assumed that there is a doi field, which maps to https://doi.org/ 

f.       The order of the article is NOT important. i.e., it is okay to have any of these fields above or below other fields;

g.      It is also assumed that empty lines can be there within the body of the articles, as well as between different articles;

h.      HOWEVER (read carefully), any of the input files may have some of these fields as empty; i.e. number={}, title={}, etc. This is what we classify as an Invalid File. In other words, for a file to be valid, the file cannot have an empty field at any of its articles. Below is an image of an invalid file.    

 

 

Figure 1. Example of an Invalid Input File 

 

 

2.      Write an exception class called FileInvalidException exception. The class should have sufficient constructors allow:  

a. A default error message “Error: Input file cannot be parsed due to missing information 

(i.e. month={}, title={}, etc.) “ to be stored in the thrown object; and  

b. The passing of any different error message if desired. This is actually the constructor that you will be using throughout the assignment (see Figure 3 below).

 

3.      In the main() method of the BibilographyFactory class, attempt to open all 10 input files (Latex1.bib to Latex10.bib) for reading. You need to use the Scanner class for the reading these files. If “any” of these files does not exist, the program must display an error message indicating “Could not open input file xxxxx  for reading. Please check if file exists! Program will terminate after closing any opened files.”, and then exits. You MUST however, close all opened files before exiting the program. For example, if Latex3.bib does not exist, then the following image shows the behavior of the program.

 

  

Figure 2. Example of Program Termination – One of the Input Files does not Exist 

 

4.      If all 10 input files can successfully be opened, the program will attempt to open/create all 30 output files (IEEE1.json to IEEE10.json, ACM1.json to ACM10.json, and NJ1.json to NJ10.json). You need to use PrintWriter to open these output files. If “any” of these output files cannot be created, then you must:

a.      Display a message to the user indicating which file could not be opened/created;

b.      Delete all other created output files (if any). That is, if you cannot create all of these output files, then you must clean the directory by deleting all other created files;

c.      Close all opened input files; then exit the program.  

 

 If you reach this step, then all 10 input files have been opened and all 30 output files have also been created (however, they are surely empty).  

 

5.      Write a method (you should take advantage of static throughout the entire assignment!) called processFilesForValidation. This method will represent the core engine for processing the input files and creating the output ones. You can pass any needed parameters to this method, and the method may return any needed information. This method however must NOT declare any exceptions. In other words, all needed handling of any exceptions that may occur within this method, must be handled by the method. In specific:

a.      The method should work on the already opened files;

b.      A method must process each of these files to find out whether it is valid or not;

c.      If a file is valid, then the method must create the proper records for each of the 3 formats

(IEEE, ACM and NJ) and store them in these files;

d.      If a file is invalid, then the method must stop the processing of this file only, throws FileInvalidException to display the exception error message, then display a message indicating which file was detected as invalid, and where the “first” problem in that file was detected (See Figure 3). The corresponding output file MUST then be deleted;

e.      The method will then continue with the processing of the following file.  

 

 

For instance, let us assume that the given input files (these files can be any files and they are not restricted to the ones provided with the assignment; in fact, the marker will execute your assignment with different files; so your code must work correctly for any given files) have 3 invalid files, Latex3.bib, Latex4.bib and Latex8.bib. Your program must detect these invalid files and show the following:

 

  

Figure 3. Example of Processing – Number of Invalid Files and Particular Fields are Indicated 

 

 

6.      Again, once the processing is done, all unsuccessfully created files MUST be deleted. Here is how the directory would look like at this point based on the above senario:

 

  

Figure 4. Contents of Current Directory after above processing Example

 

7.      Finally, at this point, the program needs to ask the user to enter the name of one of the created output files to display. If the user enters an invalid name, a FileNotFoundException should be thrown; however, the user is allowed a second and final chance to enter another name. If this second attempt also fails, then the program exits. Figure 5 and Figure 6 below show the behavior of this program. You must however apply the following:  

- If the entered file is valid, then your program must open this file for reading using the BufferedReader class. Do not use the Scanner class to read the file for that task.  

 

8.      Finally, here are some general information:

a.      It may assist you greatly if you take advantage of static variables/attributes and static attributes throughout the assignment; in fact, it is not necessary to utilize other aspects such as Inheritance, Polymorphism, etc.

b.      You must exactly match the format and look of the expected output files. For instance, use & or et al. for the authors as expected, follow the exact order/format of the contents, use vol. instead of volume when as expected. In other words, a small difference in the expected output will surely result in mark deduction;

c.      For the processing of the authors, you may want to use the StringTokenizer class;

d.      You should minimize opening and closing the files as much as possible; a better mark will be given for that;

e.      Do not use any external libraries or existing software to produce what is needed; that will directly result in a 0 mark!  

f.       Again, your program must work for any input files. The files provided with this assignment are only one possible version, and must not be considered as the general case when writing your code.   

g.      To make sure that the requirments are very clear to you, Figure 7 given an image (partially) of a sample input file, and Figures 8, 9 & 10 show the output of this sample file in the 3 formats. These files are also provided with the assignment.  

 

 

   

Figure 5. Example of Double-Fault for Displaying an Output File

 

 

  

 

Figure 6. Example of Displaying the Contents of a Successfully Created Output File

 

   

Figure 7. Example of a Sample Bib Input File – Partial Image  

 

  

Figure 8. The Created IEEE File for the above Sample Bib File

 

  

Figure 9. The Created ACM File for the above Sample Bib File

 

  

Figure 10. The Created Natural Journal File for the above Sample Bib File

More products