[develop | DONE | ADDED]: app.component.ts: Added commented code for parsing file for new FoS codes/labels.

This commit is contained in:
Konstantina Galouni 2024-09-10 01:10:05 +03:00
parent 623eb2fad0
commit 0879a339ff
1 changed files with 224 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import {AlertModal} from './openaireLibrary/utils/modal/alert';
import {NotificationHandler} from "./openaireLibrary/utils/notification-handler";
import {QuickContactService} from './openaireLibrary/sharedComponents/quick-contact/quick-contact.service';
import {LayoutService} from './openaireLibrary/dashboard/sharedComponents/sidebar/layout.service';
import {ISVocabulariesService} from "./openaireLibrary/utils/staticAutoComplete/ISVocabularies.service";
@Component({
selector: 'app-root',
@ -38,6 +39,12 @@ import {LayoutService} from './openaireLibrary/dashboard/sharedComponents/sideba
description="OpenAIRE Explore: Over 100M of research deduplicated, 170K research software, 11M research data. One of the largest open scholarly records collection worldwide."></schema2jsonld>
<div [class.uk-hidden]="loading" [ngClass]="rootClass">
<div id="modal-container"></div>
<!-- <span class="js-upload" uk-form-custom>-->
<!-- <input id="exampleInputFile" class="uk-width-medium" type="file" (change)="fileChangeEvent($event)"/>-->
<!-- <span class="uk-link " style="text-decoration: underline;">Parse NEW FOS</span>-->
<!-- </span>-->
<!-- <a (click)="checkDifferences()" class="uk-margin-left uk-link ">Check if different FOS codes/labels</a>-->
<main>
<router-outlet></router-outlet>
</main>
@ -84,9 +91,224 @@ export class AppComponent implements AfterViewInit {
private router: Router, private userManagementService: UserManagementService, private smoothScroll: SmoothScroll,
private configurationService: ConfigurationService, private _meta: Meta, private seoService: SEOService,
private emailService: EmailService, private fb: FormBuilder, private quickContactService: QuickContactService,
private layoutService: LayoutService, private cdr: ChangeDetectorRef) {
private layoutService: LayoutService, private cdr: ChangeDetectorRef,
private ISVocabulariesService: ISVocabulariesService) {
}
// fileChangeEvent(fileInput: any) {
// let file = <Array<File>>fileInput.target.files;
// this.parseNewFos(file);
// }
//
// makeFileRequest(url: string, params: Array<string>, files: Array<File>) {
// return new Promise<void>((resolve, reject) => {
// const formData: any = new FormData();
// const xhr = new XMLHttpRequest();
// for (let i = 0; i < files.length; i++) {
// formData.append("uploads[]", files[i], files[i].name);
// }
// xhr.onreadystatechange = function () {
// if (xhr.readyState == 4) {
// if (xhr.status == 200) {
// resolve(xhr.response);
// } else {
// reject(xhr.response);
// }
// }
// }
//
// xhr.open("POST", url, true);
// xhr.send(formData);
// });
// }
//
// parseNewFos(file: Array<File>) {
// let fos = null;
// this.makeFileRequest(this.properties.utilsService + '/upload', [], file).then((result) => {
// this.ISVocabulariesService.getFos(properties).subscribe(fosRes => {
// fos = fosRes['fos'];
// for(let fieldL1 of fos) {
// if(fieldL1.children != null) {
// for (let fieldL2 of fieldL1.children) {
// if(fieldL2.children != null) {
// for (let fieldL3 of fieldL2.children) {
// if(fieldL3.children != null)
// fieldL3.children = [];
// }
// }
// }
// }
// }
// // console.log(fos);
// let setOfCodes: Set<string> = new Set<string>();
// let duplicates = new Map<string, string[]>;
// const rows = (result as any).split('\n'); // I have used space, you can use any thing.
// let added = false;
// for (let i = 0; i < (rows.length); i++) {
// if (rows[i] && rows[i] != null && rows[i] != "") {
// added = false;
// let code = rows[i].split(' ')[0];
// if(setOfCodes.has(code)) {
// console.log("SAME CODE!!!!!!!!");
// } else {
// setOfCodes.add(code);
// }
// let label = rows[i].substring(code.length+1, rows[i].length);
// // console.log(rows[i]);
// let firstLevel = rows[i].substring(0, 2);
// let secondLevel = rows[i].substring(0, 4);
// let thirdLevel = rows[i].substring(0, 6);
// for(let fieldL1 of fos) {
// if(fieldL1.code == firstLevel) {
// for(let fieldL2 of fieldL1.children) {
// if(fieldL2.code == secondLevel) {
// for(let fieldL3 of fieldL2.children) {
// if(fieldL3.code == thirdLevel) {
// if(fieldL3.children == null) {
// fieldL3.children = [];
// }
// fieldL3.children.push({
// "code": code,
// "id": rows[i],
// "label": label,
// "level": 4
// })
// added = true;
// break;
// }
// }
// if(!added && (!fieldL2.children || fieldL2.children.filter(field => field.code == thirdLevel).length == 0)) {
// console.log("Level 3 not found for "+rows[i]);
// }
// break;
// }
// }
// if(!added && (!fieldL1.children || fieldL1.children.filter(field => field.code == secondLevel).length == 0)) {
// console.log("Level 2 not found for "+rows[i]);
// }
// break;
// }
// }
//
// if(!added && fos.filter(field => field.code == firstLevel).length == 0) {
// console.log("Level 1 not found for |"+rows[i]+"|");
// }
// }
// }
//
// for(let l1 of fos) {
// if(duplicates.has(l1.label)) {
// duplicates.get(l1.label).push(l1.id);
// } else {
// duplicates.set(l1.label, [l1.id]);
// }
// if(l1.children) {
// for (let l2 of l1.children) {
// if(duplicates.has(l2.label)) {
// duplicates.get(l2.label).push(l2.id);
// } else {
// duplicates.set(l2.label, [l2.id]);
// }
//
// if(l2.children) {
// for(let l3 of l2.children) {
// if(duplicates.has(l3.label)) {
// duplicates.get(l3.label).push(l3.id);
// } else {
// duplicates.set(l3.label, [l3.id]);
// }
//
// if(l3.children) {
// for(let l4 of l3.children) {
// if(duplicates.has(l4.label)) {
// duplicates.get(l4.label).push(l4.id);
// } else {
// duplicates.set(l4.label, [l4.id]);
// }
// }
// }
// }
// }
// }
// }
// }
//
// for(let label of duplicates.keys()) {
// if(duplicates.get(label).length > 1) {
// console.log(label, duplicates.get(label));
// }
// }
// var url = window.URL.createObjectURL(new Blob([JSON.stringify(fos)]));
// var a = window.document.createElement('a');
// window.document.body.appendChild(a);
// a.setAttribute('style', 'display: none');
// a.href = url;
// a.download = "fosNewL4.json";
// a.click();
// window.URL.revokeObjectURL(url);
// a.remove(); // remove the element
//
// // var theJSON = JSON.stringify(fos);
// // var uri = this.sanitizer.bypassSecurityTrustUrl("data:text/json;charset=UTF-8," + encodeURIComponent(theJSON));
// // this.downloadJsonHref = uri;
// // console.log(fos);
// });
// });
// }
//
// checkDifferences() {
// this.ISVocabulariesService.getIndexedFosL4(properties).subscribe(fosRes => {
// console.log(fosRes);
// this.ISVocabulariesService.getFos(properties).subscribe(currentFos => {
// console.log(currentFos);
// let currentSet: Map<string, string> = new Map<string, string>();
// for(let currentL1 of currentFos['fos']) {
// if(currentL1.children?.length > 0) {
// for(let currentL2 of currentL1.children) {
// if(currentL2.children?.length > 0) {
// for(let currentL3 of currentL2.children) {
// if(currentL3.children?.length > 0) {
// for(let currentL4 of currentL3.children) {
// if(currentSet.has(currentL4.code)) {
// console.log("ALREADY HERE ",currentL4.code);
// }
// currentSet.set(currentL4.code, currentL4.label);
// }
// }
// }
// }
// }
// }
// }
//
// console.log(currentSet);
// for (let fos of fosRes) {
// if(!currentSet.has(fos.l4code)) {
// console.log(fos.l4code + " does not exist in current voc");
// } else {
// if(currentSet.get(fos.l4code) != fos.l4label) {
// console.log(fos.l4code + " different label");
// }
// }
// }
//
// for(let code of currentSet.keys()) {
// let found = false;
// for(let fos of fosRes) {
// if(fos.l4code == code) {
// found = true;
// break;
// }
// }
// if(!found) {
// console.log("current code "+code+" not indexed");
// }
// }
// });
// });
// }
ngOnInit() {
if (typeof document !== 'undefined') {
this.isClient = true;