-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Order): Creation of an automatic default order for properties fr…
…om ontologies, to be used when no order defined in Vocabulary OpenSILEX/opensilex-dev!1186
- Loading branch information
HART Maximilian
committed
Mar 14, 2024
1 parent
98df2ab
commit 3bbf00e
Showing
12 changed files
with
432 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
opensilex-core/src/main/java/org/opensilex/core/ontology/api/PropertiesByDomainDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.opensilex.core.ontology.api; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.opensilex.sparql.response.ResourceTreeDTO; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
public class PropertiesByDomainDTO { | ||
|
||
PropertiesByDomainDTO(URI domain, List<ResourceTreeDTO> properties){ | ||
this.domain = domain; | ||
this.properties = properties; | ||
} | ||
|
||
@JsonProperty("domain") | ||
URI domain; | ||
|
||
@JsonProperty("properties") | ||
List<ResourceTreeDTO> properties; | ||
|
||
public URI getDomain() { | ||
return domain; | ||
} | ||
|
||
public void setDomain(URI domain) { | ||
this.domain = domain; | ||
} | ||
|
||
public List<ResourceTreeDTO> getProperties() { | ||
return properties; | ||
} | ||
|
||
public void setProperties(List<ResourceTreeDTO> properties) { | ||
this.properties = properties; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
opensilex-front/front/src/components/ontology/OntologyTools.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import {VueRDFTypeDTO, VueRDFTypePropertyDTO} from "../../lib"; | ||
import OpenSilexVuePlugin from "../../models/OpenSilexVuePlugin"; | ||
import {ResourceTreeDTO} from "opensilex-core/model/resourceTreeDTO"; | ||
|
||
interface NameAndUri{ | ||
name: string, | ||
uri: string | ||
} | ||
|
||
/** | ||
* @param properties properties to sort according {@link typeModel} {@link VueRDFTypeDTO#properties_order} | ||
* @param typeModel the type from which the properties originate from | ||
* @param opensilex opensilexVuePlugin | ||
* @return sorted properties if {@link typeModel} has a non null or empty {@link VueRDFTypeDTO#properties_order}, return properties else | ||
* Precondition : typeModel has a properties order | ||
*/ | ||
export function sortProperties(properties: Array<VueRDFTypePropertyDTO>, typeModel: VueRDFTypeDTO, opensilex: OpenSilexVuePlugin): Array<VueRDFTypePropertyDTO>{ | ||
|
||
//Create property-index map from the properties_order list to use during the sort | ||
let propertyToOrderIndexMap : Map<string, number> = new Map<string, number>(); | ||
|
||
for(let orderIndex = 0; orderIndex < typeModel.properties_order.length; orderIndex++){ | ||
propertyToOrderIndexMap.set(typeModel.properties_order[orderIndex], orderIndex); | ||
} | ||
return properties.sort((propModel1, propModel2) => { | ||
let property1 = propModel1.uri; | ||
let property2 = propModel2.uri; | ||
if (property1 === property2) { | ||
return 0; | ||
} | ||
|
||
// always put name (rdfs:label) in first | ||
if (opensilex.checkURIs(property1, opensilex.Rdfs.LABEL)) { | ||
return -1; | ||
} | ||
|
||
if (opensilex.checkURIs(property2, opensilex.Rdfs.LABEL)) { | ||
return 1; | ||
} | ||
|
||
let aIndex = propertyToOrderIndexMap.get(property1); | ||
let bIndex = propertyToOrderIndexMap.get(property2); | ||
|
||
if (aIndex === -1) { | ||
if (bIndex === -1) { | ||
return property1.localeCompare(property2); | ||
} else { | ||
return -1; | ||
} | ||
} else { | ||
if (bIndex === -1) { | ||
return 1; | ||
} else { | ||
return aIndex - bIndex; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Creates a list of every property uri that appears in a list of ResourceTreeDTOs, ordered by name | ||
*/ | ||
export function createUriListFromGetPropertiesResult(propertyList : Array<ResourceTreeDTO>, opensilex: OpenSilexVuePlugin) : Array<string>{ | ||
let nameUriUnorderedList: Array<NameAndUri> = createNameUriListFromGetPropertiesResult(propertyList, opensilex); | ||
let nameUriOrderedList: Array<NameAndUri> = nameUriUnorderedList.sort((a, b) => { | ||
if(!a.name){ | ||
return 1; | ||
} | ||
if(!b.name){ | ||
return -1; | ||
} | ||
return a.name.localeCompare(b.name); | ||
}); | ||
return nameUriOrderedList.map(e => e.uri); | ||
} | ||
|
||
/** | ||
* Recursive function to look in children, children of children, etc... | ||
* To create a list of every {uri, name} of every property that appears in an array of ResourceTreeDTOs | ||
*/ | ||
function createNameUriListFromGetPropertiesResult(propertyList : Array<ResourceTreeDTO>, opensilex: OpenSilexVuePlugin) : Array<NameAndUri>{ | ||
let result = []; | ||
propertyList.forEach(e => { | ||
result.push({uri: opensilex.getShortUri(e.uri), name: e.name}); | ||
if(e.children && e.children.length > 0){ | ||
result.push(...createNameUriListFromGetPropertiesResult(e.children, opensilex)); | ||
} | ||
}); | ||
return result; | ||
} |
Oops, something went wrong.