microsoft / semantic-link-labs

Early access to new features for Microsoft Fabric's Semantic Link.
MIT License
178 stars 37 forks source link

Function to add synonyms for tables and columns #89

Open aakashb14 opened 3 months ago

aakashb14 commented 3 months ago

What are you trying to achieve? We are trying to add synonyms for tables and columns in our direct lake model using a lakehouse table which has the synonyms as a comma separated list. Right now, synonyms must be added manually which is very time consuming for a model with 100+ tables and 1000+ columns. We want to exploit Copilot and Q&A features and need to enter synonyms programmatically.

What have you tried so far? We tried various options to see if the "synonyms" property that appears in tabular editor can be accessed via sempy labs so the synonyms in lakehouse table can be directly applied but haven't been able to find any function that exposes this property.

Is there a way to do this using sempy labs?

m-kovalsky commented 3 months ago

Currently, there is no documented schema for this in TOM. It's just a big section of json. I've parsed through it to get a list of they table, column, measure & hierarchy synonyms and am looking into adding synonyms. It would be a function like this (one for tables, one for columns, one for measures etc.).

def add_table_synonym(dataset: str, culture_name: str, table_name: str, synonym_name: str, weight: Optional[Decimal] = None, workspace: Optional[str] = None):
aakashb14 commented 3 months ago

Thank you! I managed to write a code to parse out the json and update the synonyms. One error I ran into is if the "Content" property is not set to the base JSON code in tabular editor, I get an error message. I've noted the error and the base JSON code below.

Error msg: AttributeError: 'NoneType' object has no attribute 'Content'

Base JSON code: {"Version":"1.2.0","Language":"en-US","DynamicImprovement":"None","Entities":{}}

I'm using LinguisticMetadata.Content property within Cultures in TOM to update the json and it works only when JSON is set to the base JSON code.

Any idea how this error can be fixed using code rather than manual intervention?

m-kovalsky commented 3 months ago

If you have a culture with no 'base JSON code' it is a problem. Creating the 'Content' as json code gives an error. It does accept XML code but then it stays as XML and doesn't auto-convert to json so it is problematic. Need to sort out how to populate the Content if the base JSON code isn't there.