If only people would use this phrase more often instead of “it’s impossible”. Recently I’ve heard that it’s impossible to export LQA settings from memoQ server via API. And I’ll use this post to explain it’s not true. Plus, I believe it would be interesting to get familiar with a bit broken format of mqres file. Which is an XML, like most things in memoQ’s world.
We’ll start by downloading the settings. First, you need to know what to download and for that we’ll use ListResources(ResourceType, LightResourceListFilter) method from Light resource API. As you can see it take two arguments, first is enum ResourceType from which you want LQA. The other one is LightResourceListFilter where you can specify LanguageCode and/or NameOrDescription to search for. You’ll receive back an array of LightResourceInfo from which you actually only need Guid.
Now, you have to call ExportResource(ResourceType, Guid), use the same ResourceType you’ve used when listing resources and the Guid of the resource you want to download. You’ll receive another Guid which you’ll use with File upload/download API. The page contains sample code which you could use, so I’ll skip the details here. However, this API has some quirks which are definitely worth another post. Maybe I’ll write it someday.
OK, you now have your file. Let’s see what’s inside. Even if you’re not an expert on XML you should immediately see what’s wrong here.
<MemoQResource ResourceType="LQA" Version="1.O"> <Resource> <Guid>132b980-9782-42f4-b4g3-a45d9c5d4c6d</Guid> <FileName>Basic_LQA.mqres</FileName> <Name>Basic_LQA</Name> <Description>Some description.</Description> </Resource> </MemoQResource> <?xml version="1.0" encoding="utf-8"?>
Yes, first 8 lines is XML root element
MemoQResource, and then we have a XML declaration. It’s obviously wrong. Well-formed XML should start with a declaration and have only one root element, but there are two.
<XMLSerializedLQAModel xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Version>1</Version> <Name>Basic_LQA</Name> <RevisionID>b32a2784-07e4-4b04-65ve-3832493c6670</RevisionID> <UseSeverityLevels>true</UseSeverityLevels> <UsePenaltyPoints>true</UsePenaltyPoints> <RequiresReviewerCommenting>false</RequiresReviewerCommenting> <SeverityLevelNames> <string>Minor</string> <string>Major</string> <string>Critical</string> </SeverityLevelNames> <ModelEntries> <ModelEntry> <CategoryName>Accuracy</CategoryName> <SubcategoryName>omission</SubcategoryName> <CatSubcatDescriptor> <ErrorCategoryComment>Translation is not accurate</ErrorCategoryComment> <SeveritiesAndPenalties> <SeverityWithPenalty> <SeverityIdx>0</SeverityIdx> <PenaltyPoint>1</PenaltyPoint> </SeverityWithPenalty> </SeveritiesAndPenalties> </CatSubcatDescriptor> </ModelEntry> </ModelEntries> <PassFailCriterion> <CountMultipleErrorOccuranceAsOne>true</CountMultipleErrorOccuranceAsOne> <CritDefType>NormalizedPenaltyscore</CritDefType> <PenaltyPointsNominator>0</PenaltyPointsNominator> <PenaltyPointPerWordsDenominator>1</PenaltyPointPerWordsDenominator> <NormalizedPenaltyScoreLimit>0.89</NormalizedPenaltyScoreLimit> </PassFailCriterion> <QALQAMapping /> <Timestamp>2022-10-31T15:32:46.5736226Z</Timestamp> </XMLSerializedLQAModel>
Then we have our main root element
XMLSerializedLQAModel which is where the data we’re looking for is. So, even though the file isn’t a well-formed XML we can still read it. It’s just a matter of skipping first 8 lines, and deserialising everything else from XML. In Visual Studio you can even use Paste XML As Classes functionality. It’ll generate some really ugly piece of code, but you then only need to add 3 lines of code to deserialise LQA settings into an object. Well 4, because you need to skip first 8 lines, remember? And now you can do whatever you want with it.
I’ve written all of that not to brag how knowledgeable I am, nor to diss the person who’s said it’s not possible. This person wasn’t even an engineer. Nobody knows everything. And I’ve been in the place where I didn’t know something more often than not. I just want to say that people shouldn’t communicate in absolutes. And that you should always hire people who’re willing to learn and explore, rather than people who know what you need right now. Although I appreciate it’s not always possible.
When I was starting my previous job I was hired to handle memoQ and Plunet. I didn’t know anything about these systems. Hell, when I’ve received the offer was the first time I’ve heard about these tools. And now I’m quite fluent in both. I realise it’s hard to test if somebody is willing to learn, even harder to check a person is creative. But it’s definitely worth to try, because if you’ll find such employee impossible becomes possible.
And to all engineers out there, RTFM!