 -- A Swedish man who was convicted of rape had his charges overturned after an appeals court found the man could have been asleep during the attack and cited "sexomnia" as a reason he should be released.

Mikael Halvarsson was acquitted of rape this month after experts said he was asleep during the attack and had no memory of the incident, according to a translated court ruling from the Sundsvall appeals court in Sweden.

Halvarsson was accused after the victim woke up as Halvarsson allegedly assaulted her on April 2, 2014. They had been sleeping in the same bed, but they each had their own blanket, according to the translated court documents, which also noted that she called the police the next morning, and they found Halvarsson still asleep in her bed when they arrived.

In the appeal, Halvarsson's previous girlfriend testified that he had previously tried once to have sex with her when she was sleeping. When she stopped him, he then acted confused and asked what had happened.

His mother also confirmed that he had disturbed sleeping patterns before.

While the term sexomnia may seem made up for the purposes of getting away with a crime, Dr. Kingman Strohl, a professor of medicine and director of research at the Sleep Center at Case Medical Center in Cleveland, confirmed it's an actual medical diagnosis that includes unintentional sexual behaviors during sleep.

How Did this Sleepwalker Survive Falling Off a Cliff?

How Sleep Apnea Testing Could Save Lives

Treating Depression By Treating Insomnia

Strohl, who has no connection to the case in Sweden, said that sexomnia is one kind of parasomnia or undesirable behavior or experience during sleep. More common parasomnias can include sleepwalking or sleep talking.

“Usually people are very scared and also quite confused as to what's going on," Strohl said of patients who report sexomnia. "We look for signs,” of the behavior in the patient’s past, he said. That it has “gone on before and occurs in context of sleep walking and sleep talking."

Strohl said in cases of parasomnias, a person isn't usually dreaming but instead they are undertaking an automatic action, such as walking across a room, drawing a bath, or even driving around the block. According to Strohl, these kinds of sleep behaviors are more common if a person is very tired or has taken sleep aids.

Even though sexomnia is rare, Strohl said there are clear questions and diagnosis tools to figure out if a person suffers from the sleep disorder.

If a person is on trial and wants to claim they were asleep when they allegedly committed a crime, Strohl said doctors had to be particularly careful that people aren't trying to lie about their symptoms.

"You want to know how people react to it. You want to know what the people look like and want to know how each partner reacts to it," said Strohl of diagnosing a sexomnia incident. "You don't want to encourage unwanted sexual advances."

A person who is actually asleep will not have very refined actions or be responsive to their surroundings, Strohl said. For example, a sleepwalker will start walking into a chair and make no move to get around it.

Red flags that could signal a person is faking symptoms would include actions that are more refined and responsive, Strohl said. For example, a person might try to bake a cake in their sleep, but they won't finish baking the cake and then ice it if they are asleep.

Dr. Mark Eric Dyken, a professor of neurology and director of the sleep disorder clinic at the University of Iowa, said he's seen people who attempted to blame parasomnia for their actions.

Dyken said doctors have to be careful to remember that while sexomnia is a real and studied sleep disorder, it is also very rare.

"There are bad people and there are sociopaths," said Dyken, who was also not involved with the case in Sweden. "You worry about people utilizing this diagnosis."